http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10199
Revision: 10199 Author: xqt Date: 2012-05-06 15:33:28 +0000 (Sun, 06 May 2012) Log Message: ----------- use pagegenerators for generateTransclusions
Modified Paths: -------------- trunk/pywikipedia/archivebot.py
Modified: trunk/pywikipedia/archivebot.py =================================================================== --- trunk/pywikipedia/archivebot.py 2012-05-06 12:32:58 UTC (rev 10198) +++ trunk/pywikipedia/archivebot.py 2012-05-06 15:33:28 UTC (rev 10199) @@ -174,31 +174,20 @@ pass return None
-def generateTransclusions(Site, template, namespaces=[], eicontinue=''): - qdata = { - 'action' : 'query', - 'list' : 'embeddedin', - 'eititle' : template, - 'einamespace' : '|'.join(namespaces), - 'eilimit' : '100', - 'format' : 'json', - } - if eicontinue: - qdata['eicontinue'] = eicontinue - +def generateTransclusions(Site, template, namespaces=[]): pywikibot.output(u'Fetching template transclusions...') - response, result = query.GetData(qdata, Site, back_response = True) + print namespaces, Site + transclusionPage = pywikibot.Page(Site, + "%s:%s" % (Site.namespace(10), + template)) + gen = pagegenerators.ReferringPageGenerator(transclusionPage, + onlyTemplateInclusion=True) + if namespaces: + gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces, Site) + for page in gen: + yield page
- for page_d in result['query']['embeddedin']: - yield pywikibot.Page(Site, page_d['title'])
- if 'query-continue' in result: - eicontinue = result['query-continue']['embeddedin']['eicontinue'] - for page in generateTransclusions(Site, template, namespaces, - eicontinue): - yield page - - class DiscussionThread(object): """An object representing a discussion thread on a page, that is something of the form: