Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a media wiki article using Python?

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

like image 744
sheki Avatar asked Dec 21 '10 19:12

sheki


2 Answers

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')
like image 153
Sal9K Avatar answered Sep 19 '22 03:09

Sal9K


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.

like image 30
Shadow Avatar answered Sep 20 '22 03:09

Shadow