From f32efc16ea490546bd394915c2a5345a6298199d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Michael=20O=2E=20Hegg=C3=B8?= <danmichaelo@gmail.com> Date: Fri, 7 Nov 2014 19:46:12 +0100 Subject: [PATCH] [#69] Add docstring for Site.api() --- mwclient/client.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mwclient/client.py b/mwclient/client.py index 2dd5c51..be4457b 100644 --- a/mwclient/client.py +++ b/mwclient/client.py @@ -161,7 +161,23 @@ class Site(object): return "<Site object '%s%s'>" % (self.host, self.path) def api(self, action, *args, **kwargs): - """ An API call. Handles errors and returns dict object. """ + """ + Perform a generic API call and handle errors. All arguments will be passed on. + + Example: + To get coordinates from the GeoData MediaWiki extension at English Wikipedia: + + >>> site = Site('en.wikipedia.org') + >>> result = site.api('query', prop='coordinates', titles='Oslo|Copenhagen') + >>> for page in result['query']['pages'].values(): + ... if 'coordinates' in page: + ... print page['title'], page['coordinates'][0]['lat'], page['coordinates'][0]['lon'] + Oslo 59.95 10.75 + Copenhagen 55.6761 12.5683 + + Returns: + The raw response from the API call, as a dictionary. + """ kwargs.update(args) if action == 'query': if 'meta' in kwargs: -- GitLab