PyMW-API - Python interface to MediaWiki API?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

PyMW-API - Python interface to MediaWiki API?

Brianna Laugher
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


--
They've just been waiting in a mountain for the right moment:
http://modernthings.org/

_______________________________________________
Mediawiki-api mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Magnus Manske-2
On 10/26/07, Brianna Laugher <[hidden email]> 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

_______________________________________________
Mediawiki-api mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Bryan Tong Minh
In reply to this post by Brianna Laugher
On 10/26/07, Brianna Laugher <[hidden email]> 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

_______________________________________________
Mediawiki-api mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Brianna Laugher
On 26/10/2007, Bryan Tong Minh <[hidden email]> wrote:
> On 10/26/07, Brianna Laugher <[hidden email]> 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


--
They've just been waiting in a mountain for the right moment:
http://modernthings.org/

_______________________________________________
Mediawiki-api mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Bryan Tong Minh
On 10/26/07, Brianna Laugher <[hidden email]> 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

_______________________________________________
Mediawiki-api mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Bryan Tong Minh
On 10/26/07, Bryan Tong Minh <[hidden email]> 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

_______________________________________________
Mediawiki-api mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Roan Kattouw
In reply to this post by Bryan Tong Minh
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
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: PyMW-API - Python interface to MediaWiki API?

Bryan Tong Minh
On 10/28/07, Roan Kattouw <[hidden email]> 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
> [hidden email]
> 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 mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/mediawiki-api