Hi I have a cron job which collects some statistics about a service. I need the cron job to update a media wiki page (append to the page) programmatically. I am using python for the cron so what are my best options, are there any examples of mediawiki/python libraries or does Media wiki expose any HTTP/REST apis which I can use (may be through an extension).
Thanks
If PyWikipediaBot is too heavy, try the Python module mwclient.
You can login, view a page’s current content, make your change and then view it in less than 10 lines (example).
import mwclient
site = mwclient.Site('en.wikipedia.org')
site.login('Pfctdayelise','password')
page = site.Pages['User:Pfctdayelise/Test']
text = page.edit()
print text.encode('utf-8')
newtext = "\n\nTesting the write api without logging in.\n"
page.save(text+newtext,summary='testing write api')
If you are running mediawiki on the same computer as the cron job, then you can use the edit.php script found in the maintanence directory.
/bin/python /opt/page_renderer.py | php /var/www/mediawiki/maintenance/edit.php -b PageTitle
In this example, /opt/page_renderer.py
outputs wiki markdown. This gets piped to the edit script which has the -b
flag (to mark it as a bot edit) and the title of the page you wish to edit.
Naturally, you can pipe from any program into the edit script, and you might need to change the path to the edit script if you have mediawiki installed somewhere different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With