2024-11-03 12:32:08 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# création de nouvel article de blog
|
2024-11-03 12:42:10 +01:00
|
|
|
# exemple de commande
|
|
|
|
# python new_article.py cipherbliss_blog fr "Création d'un blog gemini"
|
2024-11-03 12:32:08 +01:00
|
|
|
import argparse
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
# Configuration des arguments de la ligne de commande
|
|
|
|
parser = argparse.ArgumentParser(description="Générer un nouvel article en mode orgmode.")
|
|
|
|
parser.add_argument("blog_dir", help="Le nom du dossier de blog.")
|
|
|
|
parser.add_argument("lang", help="La langue de l'article.")
|
|
|
|
parser.add_argument("title", help="Le titre de l'article.")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Génération du nom de fichier org avec la date et le slug
|
|
|
|
now = datetime.now()
|
2024-11-08 17:40:06 +01:00
|
|
|
# date_string = now.strftime("%Y-%m-%d")
|
|
|
|
date_string = now.strftime("%Y%m%d%H%M%S")
|
2024-11-03 12:42:10 +01:00
|
|
|
date_string_full = now.strftime("%Y-%m-%d %H:%M:%S")
|
2024-11-08 17:40:06 +01:00
|
|
|
# date_string_full = now.strftime("%Y%m%d%H%M%S")
|
2024-11-03 12:32:08 +01:00
|
|
|
slug = args.title.lower().replace(" ", "-")
|
2024-11-11 00:58:44 +01:00
|
|
|
filename = f"sources/{args.blog_dir}/lang_{args.lang}/{date_string}_{args.blog_dir}_{slug}.org"
|
2024-11-03 12:32:08 +01:00
|
|
|
|
2024-11-03 12:42:10 +01:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
def create_uuid_property():
|
|
|
|
uuid_value = uuid.uuid4()
|
|
|
|
return f":PROPERTIES:\n:ID: {uuid_value}\n:END:\n"
|
|
|
|
|
2024-11-03 12:32:08 +01:00
|
|
|
# Écriture du fichier org
|
|
|
|
with open(filename, "w") as f:
|
2024-11-03 12:42:10 +01:00
|
|
|
f.write(f"{create_uuid_property()}")
|
2024-11-03 12:32:08 +01:00
|
|
|
f.write(f"#+TITLE: {args.title}\n")
|
2024-11-08 17:40:06 +01:00
|
|
|
f.write(f"#+CREATED: <{date_string_full}>\n")
|
|
|
|
f.write(f"#+TAGS: \n")
|
2024-11-03 12:42:10 +01:00
|
|
|
f.write(f"#+SLUG: {slug}\n")
|
2024-11-03 12:32:08 +01:00
|
|
|
f.write(f"#+BLOG: {args.blog_dir}\n\n")
|
|
|
|
f.write(f"* {args.title}\n\n")
|
2024-11-08 17:40:06 +01:00
|
|
|
# f.write(f"[{date_string}]\n\n")
|
2024-11-03 12:32:08 +01:00
|
|
|
|
|
|
|
print(f"Le fichier '{filename}' a été créé avec succès.")
|