http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9903
Revision: 9903 Author: drtrigon Date: 2012-02-17 12:19:57 +0000 (Fri, 17 Feb 2012) Log Message: ----------- Adding capabilities of DrTrigonBot 'textlib' script; 'glue_template_and_params' (inverse function to 'extract_templates_and_params')
Modified Paths: -------------- trunk/pywikipedia/pywikibot/textlib.py
Modified: trunk/pywikipedia/pywikibot/textlib.py =================================================================== --- trunk/pywikipedia/pywikibot/textlib.py 2012-02-17 11:34:20 UTC (rev 9902) +++ trunk/pywikipedia/pywikibot/textlib.py 2012-02-17 12:19:57 UTC (rev 9903) @@ -880,3 +880,19 @@ # Add it to the result result.append((name, params)) return result + + +def glue_template_and_params(template_and_params): + """Return wiki text of template glued from params. + + You can use items from extract_templates_and_params here to get + an equivalent template wiki text (it may happen that the order + of the params changes). + """ + (template, params) = template_and_params + + text = u'' + for item in params: + text += u'|%s=%s\n' % (item, params[item]) + + return u'{{%s\n%s}}' % (template, text)
pywikipedia-svn@lists.wikimedia.org