🚧 post to wiki
This commit is contained in:
parent
c7b73fa46a
commit
24939a76bd
1 changed files with 31 additions and 0 deletions
31
4_post_to_wiki.py
Normal file
31
4_post_to_wiki.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import os
|
||||||
|
import mwclient
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from config import *
|
||||||
|
|
||||||
|
# Template strings
|
||||||
|
HIDDEN_COMMENT = '<!-- This page is auto-generated. Do not edit manually. -->'
|
||||||
|
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}")
|
Loading…
Add table
Add a link
Reference in a new issue