The historial.json file stores metadata about all generated stories organized by month. The script uses this file to build the sidebar navigation menu and track which stories have been generated.
The file uses UTF-8 encoding to properly handle Spanish characters and special symbols.
Here’s actual data from the Historia Diaria project:
{ "Febrero 2026": [ { "titulo": "Error", "archivo": "historia-2026-02-28.html" }, { "titulo": "Error", "archivo": "historia-2026-02-27.html" }, { "titulo": "El Eco de los Días Perdidos", "archivo": "historia-2026-02-26.html" }, { "titulo": "El Eco del Ayer", "archivo": "historia-2026-02-25.html" }, { "titulo": "El Último Encantamiento Cuántico", "archivo": "historia-2026-02-24.html" }, { "titulo": "El Reloj de los Suspiros", "archivo": "historia-2026-02-23.html" }, { "titulo": "El Eco de los Espejos", "archivo": "historia-2026-02-22.html" }, { "titulo": "El Último Tejido", "archivo": "historia-2026-02-21.html" }, { "titulo": "El Último Eco de la Fuente", "archivo": "historia-2026-02-20.html" } ], "Marzo 2026": [ { "titulo": "El Guardián del Faro de las Sombras", "archivo": "historia-2026-03-04.html" }, { "titulo": "El Guardián del Laberinto Cuántico", "archivo": "historia-2026-03-03.html" }, { "titulo": "El Código de las Estrellas", "archivo": "historia-2026-03-02.html" }, { "titulo": "El Coleccionista de Suspiros", "archivo": "historia-2026-03-01.html" } ]}
Notice the “Error” entries on Feb 27-28 - these indicate failed API calls where the fallback error story was generated.
If a story with today’s filename is found, update its title instead of creating a duplicate.
4
Insert new entry if needed
if not historia_actualizada: historial[llave_mes].insert(0, { "titulo": nuevo_titulo, "archivo": nombre_archivo_hoy })
New stories are inserted at position 0 to keep the most recent first.
5
Save back to file
with open('historial.json', 'w', encoding='utf-8') as f: json.dump(historial, f, ensure_ascii=False, indent=4)
Note the ensure_ascii=False parameter to preserve Spanish characters.
Why Update Instead of Duplicate?
If the GitHub Action runs multiple times in one day (due to manual triggers or workflow re-runs), this logic prevents duplicate entries in the sidebar menu.Without this logic:
The history data is transformed into HTML for the sidebar menu:
menu_html = ""for mes, historias in historial.items(): menu_html += f'<h3 class="mes-titulo">{mes}</h3>' menu_html += '<ul class="lista-historias">' for item in historias: menu_html += f'<li><a href="{item["archivo"]}">{item["titulo"]}</a></li>' menu_html += '</ul>'
Output Format
<h3 class="mes-titulo">Marzo 2026</h3><ul class="lista-historias"> <li><a href="historia-2026-03-04.html">El Guardián del Faro de las Sombras</a></li> <li><a href="historia-2026-03-03.html">El Guardián del Laberinto Cuántico</a></li></ul>
The iteration order of months depends on Python’s dict ordering (insertion order in Python 3.7+). Older months appear first.