From f89a9683e0304b144fa0f631264acb00b0d01a15 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 2 Jun 2025 21:28:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20make=20output=20directories=20a?= =?UTF-8?q?=20config=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2_to_markdown.py | 8 +++++--- 3_to_mediawiki.py | 5 ++--- config.py.example | 1 + {recipes-md => out/markdown}/Cashew-Streichkäse.md | 0 {recipes-md => out/markdown}/Erbsenhummus.md | 0 .../markdown}/Erbsensuppe mit Räuchertofu.md | 0 {recipes-md => out/markdown}/GPN-Tomatenbutter.md | 0 {recipes-md => out/markdown}/Granatapfelcreme.md | 0 {recipes-md => out/markdown}/Gulaschmarmelade.md | 0 {recipes-md => out/markdown}/Kartoffelgulasch.md | 0 {recipes-md => out/markdown}/Kattis Hummus.md | 0 {recipes-md => out/markdown}/Kräuterquark.md | 0 {recipes-md => out/markdown}/Levervurst.md | 0 {recipes-md => out/markdown}/Matelade Apfel.md | 0 .../Mungobohnenhummus mit Jalapenos und Zatar.md | 0 {recipes-md => out/markdown}/Ofenkartoffeln.md | 0 .../markdown}/Rauchige Schwarze Bohnencreme.md | 0 .../markdown}/Rotes Thai Spinat Süßkartoffel-Curry.md | 0 {recipes-md => out/markdown}/Salatdressing GPN.md | 0 {recipes-md => out/markdown}/Salsa.md | 0 {recipes-md => out/markdown}/Schwarzwaldbutter.md | 0 {recipes-md => out/markdown}/Soja-Gulasch.md | 0 .../markdown}/Veganes Pizzabaguette Käse-Räuchertofu.md | 0 .../markdown}/Veganes Pizzabaguette Ofengemüse.md | 0 .../markdown}/Veganes Pizzabaguette Tomate-Käse.md | 0 {recipes-md => out/markdown}/vegane Aioli.md | 0 26 files changed, 8 insertions(+), 6 deletions(-) rename {recipes-md => out/markdown}/Cashew-Streichkäse.md (100%) rename {recipes-md => out/markdown}/Erbsenhummus.md (100%) rename {recipes-md => out/markdown}/Erbsensuppe mit Räuchertofu.md (100%) rename {recipes-md => out/markdown}/GPN-Tomatenbutter.md (100%) rename {recipes-md => out/markdown}/Granatapfelcreme.md (100%) rename {recipes-md => out/markdown}/Gulaschmarmelade.md (100%) rename {recipes-md => out/markdown}/Kartoffelgulasch.md (100%) rename {recipes-md => out/markdown}/Kattis Hummus.md (100%) rename {recipes-md => out/markdown}/Kräuterquark.md (100%) rename {recipes-md => out/markdown}/Levervurst.md (100%) rename {recipes-md => out/markdown}/Matelade Apfel.md (100%) rename {recipes-md => out/markdown}/Mungobohnenhummus mit Jalapenos und Zatar.md (100%) rename {recipes-md => out/markdown}/Ofenkartoffeln.md (100%) rename {recipes-md => out/markdown}/Rauchige Schwarze Bohnencreme.md (100%) rename {recipes-md => out/markdown}/Rotes Thai Spinat Süßkartoffel-Curry.md (100%) rename {recipes-md => out/markdown}/Salatdressing GPN.md (100%) rename {recipes-md => out/markdown}/Salsa.md (100%) rename {recipes-md => out/markdown}/Schwarzwaldbutter.md (100%) rename {recipes-md => out/markdown}/Soja-Gulasch.md (100%) rename {recipes-md => out/markdown}/Veganes Pizzabaguette Käse-Räuchertofu.md (100%) rename {recipes-md => out/markdown}/Veganes Pizzabaguette Ofengemüse.md (100%) rename {recipes-md => out/markdown}/Veganes Pizzabaguette Tomate-Käse.md (100%) rename {recipes-md => out/markdown}/vegane Aioli.md (100%) diff --git a/2_to_markdown.py b/2_to_markdown.py index 08ca5b0..d987c6d 100644 --- a/2_to_markdown.py +++ b/2_to_markdown.py @@ -7,8 +7,10 @@ from pathvalidate import validate_filename import os from tqdm import tqdm +from config import * + + include_title = False -output_dir = "recipes-md" def valid_duration(duration): @@ -114,8 +116,8 @@ def main(json_file): markdown_fn = f"{recipe.get('name', 'Untitled Recipe')}.md" validate_filename(markdown_fn) # XXX does this check directory traversal? markdown = format_recipe_to_markdown(recipe) - os.makedirs(output_dir, exist_ok=True) - with open(os.path.join(output_dir, markdown_fn), "w") as f: + os.makedirs(OUTDIR_MARKDOWN, exist_ok=True) + with open(os.path.join(OUTDIR_MARKDOWN, markdown_fn), "w") as f: f.write(markdown) if __name__ == "__main__": diff --git a/3_to_mediawiki.py b/3_to_mediawiki.py index d5ed2c4..d8b4c30 100644 --- a/3_to_mediawiki.py +++ b/3_to_mediawiki.py @@ -3,14 +3,13 @@ import subprocess from tqdm import tqdm from config import * -input_dir = "recipes-md" os.makedirs(OUTDIR_MEDIAWIKI, exist_ok=True) # Process each markdown file in the input directory -for filename in tqdm(os.listdir(input_dir)): +for filename in tqdm(os.listdir(OUTDIR_MARKDOWN)): if filename.endswith(".md"): - input_path = os.path.join(input_dir, filename) + input_path = os.path.join(OUTDIR_MARKDOWN, filename) output_filename = os.path.splitext(filename)[0] + ".mediawiki" output_path = os.path.join(OUTDIR_MEDIAWIKI, output_filename) diff --git a/config.py.example b/config.py.example index 514c8e8..da20aa9 100644 --- a/config.py.example +++ b/config.py.example @@ -7,4 +7,5 @@ WIKI_ARTICLE_PREFIX = 'GPN23:' WIKI_CATEGORY_LIST = ['GPN23', 'Rezepte', 'Gulaschkueche', 'GPN23:Rezepte'] OUTDIR = 'out' +OUTDIR_MARKDOWN = OUTDIR + '/markdown' OUTDIR_MEDIAWIKI = OUTDIR + '/mediawiki' diff --git a/recipes-md/Cashew-Streichkäse.md b/out/markdown/Cashew-Streichkäse.md similarity index 100% rename from recipes-md/Cashew-Streichkäse.md rename to out/markdown/Cashew-Streichkäse.md diff --git a/recipes-md/Erbsenhummus.md b/out/markdown/Erbsenhummus.md similarity index 100% rename from recipes-md/Erbsenhummus.md rename to out/markdown/Erbsenhummus.md diff --git a/recipes-md/Erbsensuppe mit Räuchertofu.md b/out/markdown/Erbsensuppe mit Räuchertofu.md similarity index 100% rename from recipes-md/Erbsensuppe mit Räuchertofu.md rename to out/markdown/Erbsensuppe mit Räuchertofu.md diff --git a/recipes-md/GPN-Tomatenbutter.md b/out/markdown/GPN-Tomatenbutter.md similarity index 100% rename from recipes-md/GPN-Tomatenbutter.md rename to out/markdown/GPN-Tomatenbutter.md diff --git a/recipes-md/Granatapfelcreme.md b/out/markdown/Granatapfelcreme.md similarity index 100% rename from recipes-md/Granatapfelcreme.md rename to out/markdown/Granatapfelcreme.md diff --git a/recipes-md/Gulaschmarmelade.md b/out/markdown/Gulaschmarmelade.md similarity index 100% rename from recipes-md/Gulaschmarmelade.md rename to out/markdown/Gulaschmarmelade.md diff --git a/recipes-md/Kartoffelgulasch.md b/out/markdown/Kartoffelgulasch.md similarity index 100% rename from recipes-md/Kartoffelgulasch.md rename to out/markdown/Kartoffelgulasch.md diff --git a/recipes-md/Kattis Hummus.md b/out/markdown/Kattis Hummus.md similarity index 100% rename from recipes-md/Kattis Hummus.md rename to out/markdown/Kattis Hummus.md diff --git a/recipes-md/Kräuterquark.md b/out/markdown/Kräuterquark.md similarity index 100% rename from recipes-md/Kräuterquark.md rename to out/markdown/Kräuterquark.md diff --git a/recipes-md/Levervurst.md b/out/markdown/Levervurst.md similarity index 100% rename from recipes-md/Levervurst.md rename to out/markdown/Levervurst.md diff --git a/recipes-md/Matelade Apfel.md b/out/markdown/Matelade Apfel.md similarity index 100% rename from recipes-md/Matelade Apfel.md rename to out/markdown/Matelade Apfel.md diff --git a/recipes-md/Mungobohnenhummus mit Jalapenos und Zatar.md b/out/markdown/Mungobohnenhummus mit Jalapenos und Zatar.md similarity index 100% rename from recipes-md/Mungobohnenhummus mit Jalapenos und Zatar.md rename to out/markdown/Mungobohnenhummus mit Jalapenos und Zatar.md diff --git a/recipes-md/Ofenkartoffeln.md b/out/markdown/Ofenkartoffeln.md similarity index 100% rename from recipes-md/Ofenkartoffeln.md rename to out/markdown/Ofenkartoffeln.md diff --git a/recipes-md/Rauchige Schwarze Bohnencreme.md b/out/markdown/Rauchige Schwarze Bohnencreme.md similarity index 100% rename from recipes-md/Rauchige Schwarze Bohnencreme.md rename to out/markdown/Rauchige Schwarze Bohnencreme.md diff --git a/recipes-md/Rotes Thai Spinat Süßkartoffel-Curry.md b/out/markdown/Rotes Thai Spinat Süßkartoffel-Curry.md similarity index 100% rename from recipes-md/Rotes Thai Spinat Süßkartoffel-Curry.md rename to out/markdown/Rotes Thai Spinat Süßkartoffel-Curry.md diff --git a/recipes-md/Salatdressing GPN.md b/out/markdown/Salatdressing GPN.md similarity index 100% rename from recipes-md/Salatdressing GPN.md rename to out/markdown/Salatdressing GPN.md diff --git a/recipes-md/Salsa.md b/out/markdown/Salsa.md similarity index 100% rename from recipes-md/Salsa.md rename to out/markdown/Salsa.md diff --git a/recipes-md/Schwarzwaldbutter.md b/out/markdown/Schwarzwaldbutter.md similarity index 100% rename from recipes-md/Schwarzwaldbutter.md rename to out/markdown/Schwarzwaldbutter.md diff --git a/recipes-md/Soja-Gulasch.md b/out/markdown/Soja-Gulasch.md similarity index 100% rename from recipes-md/Soja-Gulasch.md rename to out/markdown/Soja-Gulasch.md diff --git a/recipes-md/Veganes Pizzabaguette Käse-Räuchertofu.md b/out/markdown/Veganes Pizzabaguette Käse-Räuchertofu.md similarity index 100% rename from recipes-md/Veganes Pizzabaguette Käse-Räuchertofu.md rename to out/markdown/Veganes Pizzabaguette Käse-Räuchertofu.md diff --git a/recipes-md/Veganes Pizzabaguette Ofengemüse.md b/out/markdown/Veganes Pizzabaguette Ofengemüse.md similarity index 100% rename from recipes-md/Veganes Pizzabaguette Ofengemüse.md rename to out/markdown/Veganes Pizzabaguette Ofengemüse.md diff --git a/recipes-md/Veganes Pizzabaguette Tomate-Käse.md b/out/markdown/Veganes Pizzabaguette Tomate-Käse.md similarity index 100% rename from recipes-md/Veganes Pizzabaguette Tomate-Käse.md rename to out/markdown/Veganes Pizzabaguette Tomate-Käse.md diff --git a/recipes-md/vegane Aioli.md b/out/markdown/vegane Aioli.md similarity index 100% rename from recipes-md/vegane Aioli.md rename to out/markdown/vegane Aioli.md