1

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:

  1. How can I create more than one sectiontitle?
  2. 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".
sc4s2cg
  • 153
  • 9
  • Pywikibot is definitely the easiest/most versatile way, figuring out your problems with it might be easier. Most other API clients ([mwapi](https://pythonhosted.org/mwapi/) is also a nice one) just make it easy to send requests to the API but leave it to you to put together the request. So you'd have to look at the [docs](https://www.mediawiki.org/wiki/API:Edit) or the [API sandbox](https://en.wikipedia.org/wiki/Special:ApiSandbox). – Tgr Jun 09 '18 at 21:50

1 Answers1

2
  1. 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.)

  1. 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.

AXO
  • 8,198
  • 6
  • 62
  • 63