>
>
> From: Yury Katkov <[email protected]>
> To: MediaWiki announcements and site admin list <
> [email protected]>, [email protected]
> 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
> [email protected]
> https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
>
>
_______________________________________________
Pywikipedia-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l

Reply via email to