Revision: 7048 Author: filnik Date: 2009-07-13 10:06:54 +0000 (Mon, 13 Jul 2009)
Log Message: ----------- Update categoryAllPageObjectsAPI function
Modified Paths: -------------- trunk/pywikipedia/catlib.py
Modified: trunk/pywikipedia/catlib.py =================================================================== --- trunk/pywikipedia/catlib.py 2009-07-13 09:09:31 UTC (rev 7047) +++ trunk/pywikipedia/catlib.py 2009-07-13 10:06:54 UTC (rev 7048) @@ -519,7 +519,7 @@ wikipedia.output(u"Saving page %s failed: %s" % (article.aslink(), error.message))
-def categoryAllElementsAPI(CatName, cmlimit = 5000, categories_parsed = []): +def categoryAllElementsAPI(CatName, cmlimit = 5000, categories_parsed = [], site = None): #action=query&list=categorymembers&cmlimit=500&cmtitle=Category:License_tags """ Category to load all the elements in a category using the APIs. Limit: 5000 elements. @@ -533,8 +533,9 @@ 'cmtitle' :CatName, }
- data = query.GetData(params, + data = query.GetData(params, site = site, useAPI = True, encodeTitle = False) + print data categories_parsed.append(CatName) try: members = data['query']['categorymembers'] @@ -564,13 +565,15 @@ results.append(member) return (results, categories_parsed)
-def categoryAllPageObjectsAPI(CatName): +def categoryAllPageObjectsAPI(CatName, cmlimit = 5000, categories_parsed = [], site = None): """ From a list of dictionaries, return a list of page objects. """ final = list() - for element in categoryAllElementsAPI(CatName)[0]: - final.append(wikipedia.Page(wikipedia.getSite(), element['title'])) + if site == None: + site = wikipedia.getSite() + for element in categoryAllElementsAPI(CatName, cmlimit, categories_parsed, site)[0]: + final.append(wikipedia.Page(site, element['title'])) return final
def test():