Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adding {{Data template used}}
# -*- coding: utf-8 -*-
import pywikibot
import re
from pywikibot import textlib
site = pywikibot.getSite()
data_template = re.compile(".*/(Data|Box|RefFrame|Param)")
yes_all = False
for arg in pywikibot.handleArgs():
if arg in ["--all", "-a"]:
yes_all = True
for page in site.allpages():
match =
if match:
content = page.text
templates = textlib.extract_templates_and_params(content)
for template in templates:
if template[0] == "Data template used":
print("Already contain template in '{}'. Skipped.".format(page.title()))
# for didn't find
page.text = "<noinclude>{{Data template used}}</noinclude>" + content
if not yes_all:
answer = pywikibot.inputChoice("Add template to '{}'?".format(page.title()), ['Yes', 'No', 'All'], ['y', 'n', 'a'], 'n')
if answer == 'a':
yes_all = True
if yes_all or answer != 'n':"+add 'data template used' template;")
print("Edited page '{}'.".format(page.title()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment