🎨 make output directories a config option
This commit is contained in:
parent
55483e4897
commit
f89a9683e0
26 changed files with 8 additions and 6 deletions
|
@ -7,8 +7,10 @@ from pathvalidate import validate_filename
|
||||||
import os
|
import os
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
from config import *
|
||||||
|
|
||||||
|
|
||||||
include_title = False
|
include_title = False
|
||||||
output_dir = "recipes-md"
|
|
||||||
|
|
||||||
|
|
||||||
def valid_duration(duration):
|
def valid_duration(duration):
|
||||||
|
@ -114,8 +116,8 @@ def main(json_file):
|
||||||
markdown_fn = f"{recipe.get('name', 'Untitled Recipe')}.md"
|
markdown_fn = f"{recipe.get('name', 'Untitled Recipe')}.md"
|
||||||
validate_filename(markdown_fn) # XXX does this check directory traversal?
|
validate_filename(markdown_fn) # XXX does this check directory traversal?
|
||||||
markdown = format_recipe_to_markdown(recipe)
|
markdown = format_recipe_to_markdown(recipe)
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(OUTDIR_MARKDOWN, exist_ok=True)
|
||||||
with open(os.path.join(output_dir, markdown_fn), "w") as f:
|
with open(os.path.join(OUTDIR_MARKDOWN, markdown_fn), "w") as f:
|
||||||
f.write(markdown)
|
f.write(markdown)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -3,14 +3,13 @@ import subprocess
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from config import *
|
from config import *
|
||||||
input_dir = "recipes-md"
|
|
||||||
|
|
||||||
os.makedirs(OUTDIR_MEDIAWIKI, exist_ok=True)
|
os.makedirs(OUTDIR_MEDIAWIKI, exist_ok=True)
|
||||||
|
|
||||||
# Process each markdown file in the input directory
|
# 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"):
|
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_filename = os.path.splitext(filename)[0] + ".mediawiki"
|
||||||
output_path = os.path.join(OUTDIR_MEDIAWIKI, output_filename)
|
output_path = os.path.join(OUTDIR_MEDIAWIKI, output_filename)
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ WIKI_ARTICLE_PREFIX = 'GPN23:'
|
||||||
WIKI_CATEGORY_LIST = ['GPN23', 'Rezepte', 'Gulaschkueche', 'GPN23:Rezepte']
|
WIKI_CATEGORY_LIST = ['GPN23', 'Rezepte', 'Gulaschkueche', 'GPN23:Rezepte']
|
||||||
|
|
||||||
OUTDIR = 'out'
|
OUTDIR = 'out'
|
||||||
|
OUTDIR_MARKDOWN = OUTDIR + '/markdown'
|
||||||
OUTDIR_MEDIAWIKI = OUTDIR + '/mediawiki'
|
OUTDIR_MEDIAWIKI = OUTDIR + '/mediawiki'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue