Updating a media wiki article using Python?

橙三吉。 提交于 2019-12-05 19:33:54
Sal9K

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!