From 971d76121252baa3ee961982007da8d1be2fd9b5 Mon Sep 17 00:00:00 2001 From: max/sooulix Date: Sun, 7 Jul 2024 19:53:14 +0200 Subject: [PATCH] =?UTF-8?q?[script]=20new=5Fcontent=20permet=20de=20cr?= =?UTF-8?q?=C3=A9er=20les=20entete=20pour=20une=20nouvelle=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- new_content.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 new_content.py diff --git a/new_content.py b/new_content.py new file mode 100644 index 0000000..a1f68c3 --- /dev/null +++ b/new_content.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +import re +from dataclasses import dataclass +from datetime import datetime +from typing import List + +dateformat = lambda x: x.strftime("%Y-%m-%d %H:%M") +now = datetime.now() + +default_slug = lambda x: re.sub(r'[^a-z0-9_]', '', x.lower().replace(' ', '_')) + +existing_authors = [] + +# def scan_metadata(): +# metadata = {} +# for _, _, files in os.walk('./content'): +# for file in files: +# with open(file) as fh: +# content = filter(fh.readlines()) +# +# +# +# +# def read_authors(): + +@dataclass +class ContentMetadata: + title: str + date: str + modified: str + tags: List[str] + category: str + slug: str + authors: str + summary: str + + def __repr__(self): + return f""" +{self.title} +{'#' * len(self.title)} + +:date: {self.date} +:modified: {self.date} +:tags: {', '.join(self.tags)} +:category: {self.category} +:slug: {self.slug} +:authors: {self.authors} +:summary: {self.summary} +""" + + +def main(): + title = input("Title?") + date = input(f"Creation date? [{dateformat(now)}]") + if len(date) == 0: + date = dateformat(now) + + tags = [] + tag = None + while tag is None or len(tag) > 0: + if tag is not None: + tags.append(tag) + + tag = input("Add tag") + + category = input("Category?") + slug = input(f"Slug? [{default_slug(title)}]") + + if len(slug) == 0: + slug = default_slug(title) + + authors = input("Authors?") + summary = input("Summary?") + + content = ContentMetadata( + title, + date, + date, + tags, + category, + slug, + authors, + summary + ) + + with open(f'./{slug}.rst', 'w') as fh: + fh.write(str(content)) + + + + +if __name__ == '__main__': + main()