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
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue