Reputation: 163
I recently learned how to scrape my mom's recipes from a cooking website. My current goal is to put those recipes into a self-hosted mediawiki server. Since all I know is python, I'm trying to use GET and POST requests and the API to create these pages. I've tried the various python scripts, like pywikibot, mwclient, and wptools to various forms of success. Documentation is really lacking for the latter two when it comes to editing/creating wiki pages, and pywikibot has some bugs (reported) that prevent me from logging on or using the pagefromfile.py script.
Luckily, there is a sample python code on mediawiki website.
username = 'myusername'
password = 'mypassword' # see https://www.mediawiki.org/wiki/Manual:Bot_passwords
api_url = 'https://my.wiki.com/api.php'
section = 'new'
sectiontitle = 'Ingredients'
summary = 'ingredients'
message = {" \n\u2022 6 db óriási nyers padlizsán <br>"
+"\n\u2022 4 db édes, húsos piros paprika, egészben <br>"
+"\n\u2022 3 db fekete paradicsom, vastagabb karikára szelve <br>"
+"\n\u2022 1 db zöld jalapeno paprika, egészben <br>"
+"\n\u2022 2 db nagy vöröshagyma, vastagabb karikára vágva <br>"
+"\n\u2022 10 cikk fokhagyma <br>"
+"\n\u2022 1 ek édes piros paprika <br>"
+"\n\u2022 ízlés szerint só <br>"
+"\n\u2022 ízlés szerint bors <br>"
}
page = 'Test'
This code creates a page with the relevant section and message, it looks like this.
Questions:
Upvotes: 1
Views: 332
Reputation: 9086
- How can I create more than one sectiontitle?
One way would be to add a \n== section title ==\n
to the message. (Using MediaWiki markup.)
- If I put in wiki code, how come the mediawiki doesn't format it? For example, if I make the message "# 6db oriasi nyers" then mediawiki will create a message with "# 6db oriasi nyers" instead of "1. 6db oriasi nyers".
My best guess is that you are using an incorrect syntax, e.g. there is a space before the #
mark (which makes the text be treated as preformatted text).
It's hard to tell without seeing your full code.
Upvotes: 2