+ return data
+
+ def call(self, params):
+ """
+ Make a call to the wiki. Returns a dictionary that represents the JSON
+ returned by the API.
+ """
+ params['format'] = 'json'
+ return json.loads(self._fetch_http(self._api_url, params))
+
+ def normalize_api_url(self):
+ """
+ This function checks the given URL for a correct API endpoint and
+ returns that URL, while also helpfully setting this object's API URL to
+ it. If it can't magically conjure an API endpoint, it returns False.
+ """
+ def tester(self, api_url):
+ """
+ Attempts to fetch general information about the MediaWiki instance
+ in order to test whether the given URL will return JSON.
+ """
+ data = self._fetch_http(api_url, {'action': 'query',
+ 'meta': 'siteinfo'})
+ try:
+ data_json = json.loads(data)
+ return (data, data_json)
+ except ValueError:
+ return (data, None)
+
+ data, data_json = tester(self, self._api_url)
+ if data_json:
+ return self._api_url
+ else:
+ # if there's an index.php in the URL, we might find the API
+ if 'index.php' in self._api_url:
+ test_api_url = self._api_url.split('index.php')[0] + 'api.php'
+ print test_api_url
+ test_data, test_data_json = tester(self, test_api_url)
+ print (test_data, test_data_json)
+ if test_data_json:
+ self._api_url = test_api_url
+ return self._api_url
+ return False
+