From 24939a76bd2f555e7fc2366ac96b0e6e861a6b8f Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 2 Jun 2025 00:24:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20post=20to=20wiki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4_post_to_wiki.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 4_post_to_wiki.py diff --git a/4_post_to_wiki.py b/4_post_to_wiki.py new file mode 100644 index 0000000..53767b7 --- /dev/null +++ b/4_post_to_wiki.py @@ -0,0 +1,31 @@ +import os +import mwclient +import sys + +from config import * + +# Template strings +HIDDEN_COMMENT = '' +CATEGORY_TEMPLATE = '\n'.join('[[Category:{0}]]'.format(cat) for cat in CATEGORY_LIST) + +# Connect to MediaWiki +site = mwclient.Site(WIKI_HOST, path=WIKI_PATH) +site.login(USERNAME, PASSWORD) + +# Process and upload each .mediawiki file +for filename in os.listdir(DIRECTORY): + if filename.endswith('.mediawiki'): + filepath = os.path.join(DIRECTORY, filename) + article_name = ARTICLE_PREFIX + filename.replace('.mediawiki', '') + + with open(filepath, 'r', encoding='utf-8') as f: + content = f.read() + + # Compose final content + final_content = f"{HIDDEN_COMMENT}\n\n{content}\n\n{CATEGORY_TEMPLATE}" + + # Post to MediaWiki + page = site.pages[article_name] + page.save(final_content, summary='Automated upload of recipe page') + + print(f"Uploaded: {article_name}")