That's nice, thanks! ----- Yury Katkov
On Mon, Aug 6, 2012 at 8:19 PM, Max Klein isalix@gmail.com wrote:
From: Yury Katkov katkov.juriy@gmail.com To: MediaWiki announcements and site admin list mediawiki-l@lists.wikimedia.org, pywikipedia-l@lists.wikimedia.org Cc: Date: Mon, 6 Aug 2012 16:05:03 +0400 Subject: [Pywikipedia-l] Automatic generation of templates descriptions Hello! Is there a bot or extension that can generate stubs of template descriptions by template wikitext? It should be pretty simple: the bot will just grab all template parameters {{{PARAMETER}}} and lists those parameters.
If no such extensions exists could anybody tell how to programaticaly get the parameters of a given template?
Hi Yury, I actually just solved this problem myself. There is indeed a method of pywikipediabot that does this - it's called templatesWithParams()
Here is a code example where I am looking to get see what the "VIAF" parameter is of the {{Authority Control}} template:
def determineAuthorityControlTemplate(nameOfPage): """returns 'noACtemplate' if no Authority Control Template, 'templateNoVIAF' if AC template but no VIAF number, and returns the viaf number if it exists""" namepage = Page(enwp,nameOfPage) templates = namepage.templatesWithParams() #here we load the templates into a list for template in templates: # go through the templates if template[0] == 'Authority control': # are we looking at the right template? for param in template[1]: #go through the paramaters of the template if param[:4] == 'VIAF': #are we looking at the right parameter? return param[5:] return 'templateNoVIAF' return 'noACtemplate'
Best, Max
Sincerely yours,
Yury Katkov
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l