Hi,
I am thinking about starting to write a standard Python wrapper-interface thingy to the MediaWiki API. I thought I would write here first and see what people think and if anyone knows of any similar work done already (perhaps in pywikipediabot?).
The only relevant thing I found so far is http://en.wikipedia.org/wiki/User:Yurik/Query_API/User_Manual#Python
The reason I am thinking of doing it because whenever I do serious API queries (like checking a day's worth of logs) I always use Python to manipulate whatever I get back, and also because the API generally only lets you get 500 items and I haven't found a good way to loop through the log items by timestamp, if you know what I mean. And so each time I do a query I just rewrite basically the same thing and I'm sick of it, and if I'm doing this maybe other people are too.
So, thoughts?
cheers, Brianna
On 10/26/07, Brianna Laugher brianna.laugher@gmail.com wrote:
Hi,
I am thinking about starting to write a standard Python wrapper-interface thingy to the MediaWiki API. I thought I would write here first and see what people think and if anyone knows of any similar work done already (perhaps in pywikipediabot?).
My Python's a little rusty, but basically it's a sound idea. I did the same thing in PHP for my tools on the toolserver.
My 2c, Magnus
On 10/26/07, Brianna Laugher brianna.laugher@gmail.com wrote:
here first and see what people think and if anyone knows of any similar work done already (perhaps in pywikipediabot?).
About done. See http://fisheye.ts.wikimedia.org/browse/bryan/mwclient/trunk
Bryan
On 26/10/2007, Bryan Tong Minh bryan.tongminh@gmail.com wrote:
On 10/26/07, Brianna Laugher brianna.laugher@gmail.com wrote:
here first and see what people think and if anyone knows of any similar work done already (perhaps in pywikipediabot?).
About done. See http://fisheye.ts.wikimedia.org/browse/bryan/mwclient/trunk
Wow, you're onto everything, Bryan. I just need to think what I want and you've already coded it. ;)
Can you give an example of how you would e.g. get all the files uploaded on a particular day? does it do the kind of "timestamp looping" I mentioned?
cheers Brianna
On 10/26/07, Brianna Laugher brianna.laugher@gmail.com wrote:
Can you give an example of how you would e.g. get all the files uploaded on a particular day? does it do the kind of "timestamp looping" I mentioned?
It does. It is implemented using iterators, so it is actually only fetched from the server when it is asked. For example:
import mwclient site = mwclient.Site('commons.wikimedia.org') site.login(username, password) # Optional
logs = site.logevents(type = 'upload') for i in logs: print i
NB, don't do this in reality, since it will loop over the whole upload log. Try that at Commons.
Page editting:
page = site.Pages['Commons:Sandbox'] text = page.edit() page.save(text + u'\ntest', summary = 'Test edit')
Uploading:
site.Images.upload(open('file.jpg'), 'destination.jpg', 'Image description')
I guess I should clean up the code a bit and add documentation... Some not so useful docs reside at http://fisheye.ts.wikimedia.org/browse/bryan/mwclient/trunk/README.txt?r=341. I hope to get this done once I have cleaned up my todo list a bit, but it is already fairly usable.
See also some of my bots: * DRBot: http://fisheye.ts.wikimedia.org/browse/bryan/bots/drbot.py * FlickreviewR http://fisheye.ts.wikimedia.org/browse/bryan/flickreviewr * POTY 2007 software also uses mwclient to send emails. http://fisheye.ts.wikimedia.org/browse/bryan/poty2007/index.py
Bryan
On 10/26/07, Bryan Tong Minh bryan.tongminh@gmail.com wrote:
I guess I should clean up the code a bit and add documentation... Some not so useful docs reside at http://fisheye.ts.wikimedia.org/browse/bryan/mwclient/trunk/README.txt?r=341.
I added some examples at http://fisheye.ts.wikimedia.org/browse/bryan/mwclient/trunk/README.txt?r=HEAD
Have fun, Bryan
Bryan Tong Minh schreef:
Page editting:
page = site.Pages['Commons:Sandbox'] text = page.edit() page.save(text + u'\ntest', summary = 'Test edit')
Uploading:
site.Images.upload(open('file.jpg'), 'destination.jpg', 'Image description')
Please note that edit and upload functionality in the API is not implemented in trunk (the 'standard' version of MediaWiki), but only in the apiedit_Vodafone branch [1]. (Un)deletion, (un)protection, (un)blocking, rollback and user rights are implemented in the apiedit branch [2].
Roan Kattouw
[1] http://svn.wikimedia.org/viewvc/mediawiki/branches/ApiEdit_Vodafone [2] http://svn.wikimedia.org/viewvc/mediawiki/branches/apiedit
On 10/28/07, Roan Kattouw roan.kattouw@home.nl wrote:
Bryan Tong Minh schreef:
Page editting:
page = site.Pages['Commons:Sandbox'] text = page.edit() page.save(text + u'\ntest', summary = 'Test edit')
Uploading:
site.Images.upload(open('file.jpg'), 'destination.jpg', 'Image description')
Please note that edit and upload functionality in the API is not implemented in trunk (the 'standard' version of MediaWiki), but only in the apiedit_Vodafone branch [1]. (Un)deletion, (un)protection, (un)blocking, rollback and user rights are implemented in the apiedit branch [2].
Roan Kattouw
[1] http://svn.wikimedia.org/viewvc/mediawiki/branches/ApiEdit_Vodafone [2] http://svn.wikimedia.org/viewvc/mediawiki/branches/apiedit
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
mwclient still uses the normal index.php for saving pages. Edit tokens are obtained via the API.
Bryan
mediawiki-api@lists.wikimedia.org