From b111a348041be481386c68945e65071c90187419 Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 12 Jun 2025 13:40:22 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20allow=20posting=20single=20wiki=20a?= =?UTF-8?q?rticles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4_post_to_wiki.py | 25 ++++++++++++++++++++----- do-it.sh | 4 ---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/4_post_to_wiki.py b/4_post_to_wiki.py index 711ffa7..e7bd30a 100644 --- a/4_post_to_wiki.py +++ b/4_post_to_wiki.py @@ -1,5 +1,6 @@ import os import mwclient +import click import sys from tqdm import tqdm @@ -15,10 +16,20 @@ CATEGORY_TEMPLATE = "\n".join( site = mwclient.Site(WIKI_HOST, path=WIKI_PATH) site.login(WIKI_USERNAME, WIKI_PASSWORD) -# Process and upload each .mediawiki file -for filename in tqdm(os.listdir(OUTDIR_MEDIAWIKI)): - if filename.endswith(".mediawiki"): - filepath = os.path.join(OUTDIR_MEDIAWIKI, filename) + +@click.command() +@click.argument('files', nargs=-1) +def post(files): + if files[0] == "all": + files = [] + for filename in tqdm(os.listdir(OUTDIR_MEDIAWIKI)): + if filename.endswith(".mediawiki"): + filepath = os.path.join(OUTDIR_MEDIAWIKI, filename) + files.append(filepath) + + for filepath in files: + filename = os.path.basename(filepath) + article_name = WIKI_ARTICLE_PREFIX + filename.replace(".mediawiki", "") with open(filepath, "r", encoding="utf-8") as f: @@ -29,4 +40,8 @@ for filename in tqdm(os.listdir(OUTDIR_MEDIAWIKI)): # Post to MediaWiki page = site.pages[article_name] - page.save(final_content, summary="Automated upload of recipe page") + page.save(final_content, summary="U+1F916 ROBOT FACE") + + +if __name__ == "__main__": + post() diff --git a/do-it.sh b/do-it.sh index 3b612cb..2a316e4 100755 --- a/do-it.sh +++ b/do-it.sh @@ -7,7 +7,3 @@ python 0_get_recipes.py python 1_clean_json.py python 2_to_markdown.py python 3_to_mediawiki.py - -if [[ "$1" = "post" ]]; then - python 4_post_to_wiki.py -fi