mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
up date formats detection
This commit is contained in:
parent
6767f8fe50
commit
a029792664
2 changed files with 97 additions and 1 deletions
|
@ -251,7 +251,7 @@ if generate_linkings_json :
|
|||
'article_type': article_type,
|
||||
'date_modified' : date_modified,
|
||||
'first_picture_url' : get_first_picture_url(content),
|
||||
'date_formattee': datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S') if len(date_str) == 14 else datetime.strptime(date_str, '%Y%m%dT%H%M%S').strftime('%d %B %Y à %H:%M:%S') if len(date_str) == 15 else datetime.strptime(date_str, '%Y-%m-%d').strftime('%d %B %Y'),
|
||||
'date_formattee': format_date_str(date_str),
|
||||
'annee': annee,
|
||||
'tags': tags,
|
||||
'title': title,
|
||||
|
@ -498,5 +498,40 @@ generate_article_pages(destination_json + '/articles_info.json', 'templates/html
|
|||
execution_time = time.time() - start_time
|
||||
#print(f"Temps d'exécution : {execution_time:.2f} secondes")
|
||||
|
||||
def format_date_str(date_str):
|
||||
"""
|
||||
Formate une chaîne de date dans différents formats possibles
|
||||
"""
|
||||
try:
|
||||
# Format YYYYMMDDHHMMSS (14 caractères)
|
||||
if len(date_str) == 14:
|
||||
return datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S')
|
||||
|
||||
# Format YYYYMMDDTHHMMSS (15 caractères avec T)
|
||||
elif len(date_str) == 15 and 'T' in date_str:
|
||||
return datetime.strptime(date_str, '%Y%m%dT%H%M%S').strftime('%d %B %Y à %H:%M:%S')
|
||||
|
||||
# Format YYYYMMDDTHHMM (13 caractères avec T)
|
||||
elif len(date_str) == 13 and 'T' in date_str:
|
||||
return datetime.strptime(date_str, '%Y%m%dT%H%M').strftime('%d %B %Y à %H:%M')
|
||||
|
||||
# Format YYYY-MM-DD
|
||||
elif len(date_str) == 10 and '-' in date_str:
|
||||
return datetime.strptime(date_str, '%Y-%m-%d').strftime('%d %B %Y')
|
||||
|
||||
# Format YYYYMMDDTHHMMS (14 caractères avec T, manque un chiffre pour les secondes)
|
||||
elif len(date_str) == 14 and 'T' in date_str:
|
||||
# Ajouter un '0' pour compléter les secondes
|
||||
date_str = date_str + '0'
|
||||
return datetime.strptime(date_str, '%Y%m%dT%H%M%S').strftime('%d %B %Y à %H:%M:%S')
|
||||
|
||||
else:
|
||||
print(f"Format de date non reconnu: {date_str}")
|
||||
return date_str
|
||||
|
||||
except ValueError as e:
|
||||
print(f"Erreur lors du formatage de la date {date_str}: {str(e)}")
|
||||
return date_str
|
||||
|
||||
|
||||
|
||||
|
|
61
utils.py
61
utils.py
|
@ -8,6 +8,7 @@ import pypandoc
|
|||
import subprocess
|
||||
import tempfile
|
||||
from md2gemini import md2gemini
|
||||
import locale
|
||||
|
||||
from website_config import *
|
||||
|
||||
|
@ -483,6 +484,64 @@ def count_files_in_directories(directories):
|
|||
continue
|
||||
return total_count
|
||||
|
||||
def format_date_str(date_str):
|
||||
"""
|
||||
Formate une chaîne de date dans différents formats possibles
|
||||
"""
|
||||
try:
|
||||
# Définir la locale en français
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
|
||||
except:
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, 'fra')
|
||||
except:
|
||||
print("Impossible de définir la locale en français")
|
||||
|
||||
# Format YYYYMMDDHHMMSS (14 caractères)
|
||||
if len(date_str) == 14:
|
||||
if 'T' not in date_str:
|
||||
return datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S')
|
||||
else:
|
||||
# Si contient T, traiter comme YYYYMMDDTHHMM + 1 chiffre
|
||||
base_date = date_str[:12]
|
||||
return datetime.strptime(base_date, '%Y%m%dT%H%M').strftime('%d %B %Y à %H:%M')
|
||||
|
||||
# Format YYYYMMDDTHHMMSS (15 caractères avec T)
|
||||
elif len(date_str) == 15 and 'T' in date_str:
|
||||
return datetime.strptime(date_str, '%Y%m%dT%H%M%S').strftime('%d %B %Y à %H:%M:%S')
|
||||
|
||||
# Format YYYYMMDDTHHMM + chiffre optionnel (13 caractères avec T)
|
||||
elif len(date_str) == 13 and 'T' in date_str:
|
||||
# Toujours prendre les 12 premiers caractères (YYYYMMDDTHHMM)
|
||||
base_date = date_str[:12]
|
||||
return datetime.strptime(base_date, '%Y%m%dT%H%M').strftime('%d %B %Y à %H:%M')
|
||||
|
||||
# Format YYYY-MM-DD
|
||||
elif len(date_str) == 10 and '-' in date_str:
|
||||
return datetime.strptime(date_str, '%Y-%m-%d').strftime('%d %B %Y')
|
||||
|
||||
else:
|
||||
print(f"Format de date non reconnu: {date_str}")
|
||||
# Essayer d'extraire au moins la date de base
|
||||
try:
|
||||
base_date = date_str[:8] # Prendre juste YYYYMMDD
|
||||
return datetime.strptime(base_date, '%Y%m%d').strftime('%d %B %Y')
|
||||
except ValueError:
|
||||
return date_str
|
||||
|
||||
except ValueError as e:
|
||||
print(f"Erreur lors du formatage de la date {date_str}: {str(e)}")
|
||||
# En cas d'erreur, essayer de parser juste la partie date
|
||||
try:
|
||||
base_date = date_str[:8] # Prendre juste YYYYMMDD
|
||||
return datetime.strptime(base_date, '%Y%m%d').strftime('%d %B %Y')
|
||||
except ValueError:
|
||||
return date_str
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def convert_org_to_gemini(org_content):
|
||||
"""
|
||||
|
@ -576,9 +635,11 @@ Date: {article['date_formattee']}
|
|||
|
||||
{article['gemini_content']}
|
||||
-----------------------------------------------
|
||||
|
||||
{tags}
|
||||
|
||||
-----------------------------------------------
|
||||
{template_content['AUTHOR']}
|
||||
{template_content['SOUTIEN']}
|
||||
-----------------------------------------------
|
||||
Navigation:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue