import pywikibot
import sys
from difflib import context_diff
from pywikibot import pagegenerators, Timestamp
import datetime, re

site = pywikibot.Site('zh', 'wikipedia')
ensite = pywikibot.Site('en', 'wikipedia')
repo = site.data_repository()
#trasnclusion generator
referredTemplate = pywikibot.Page(site, 'Template:en')
transclusionGen = pagegenerators.ReferringPageGenerator(referredTemplate, followRedirects=False,
                           withTemplateInclusion=True,
                           onlyTemplateInclusion=True,
                           total=None, content=False)

#namespace filter
filteredTG = pagegenerators.NamespaceFilterPageGenerator(transclusionGen, 'Template', site)
count = 0
prog = re.compile("t")

aliases = ["En", "en"]

def mapif(f,cond):
    result = ""
    for i in aliases:
        result = f(i)
        if(cond(result)):
            return result
    return result
        
def checkIf(f):
    for i in aliases:
        if(f(i)):
            return f(i)
        
for page in filteredTG:
    print(page.title())
    try:
        page.text = page.text.replace("{{en}}", "{{en icon}}")
        page.save("reduce redirect:replace en with en icon ")
    except:
        print("error")
Template:Imdb title
WARNING: API error protectedpage: This page has been protected to prevent editing or other actions.
error
Template:Imdb name
Sleeping for 9.3 seconds, 2019-06-15 04:45:03
WARNING: API error protectedpage: This page has been protected to prevent editing or other actions.
error
Template:S-line
Sleeping for 8.1 seconds, 2019-06-15 04:45:15
Page [[Template:S-line]] saved
Template:Chembox/doc
Sleeping for 5.1 seconds, 2019-06-15 04:45:27
Page [[Template:Chembox/doc]] saved
Template:Imdb name/doc
Sleeping for 6.5 seconds, 2019-06-15 04:45:36
Page [[Template:Imdb name/doc]] saved
Template:Find sources
Sleeping for 7.0 seconds, 2019-06-15 04:45:46
Page [[Template:Find sources]] saved
Template:Chembox
Sleeping for 8.4 seconds, 2019-06-15 04:45:54
WARNING: API error protectedpage: This page has been protected to prevent editing or other actions.
error
Template:Authority control
Sleeping for 8.1 seconds, 2019-06-15 04:46:05
WARNING: API error protectedpage: This page has been protected to prevent editing or other actions.
error
Template:Twitter status
Sleeping for 3.7 seconds, 2019-06-15 04:46:19
Page [[Template:Twitter status]] saved
Template:User 共用IP地址
Sleeping for 9.1 seconds, 2019-06-15 04:46:24
Page [[Template:User 共用IP地址]] saved
Template:Cite NSRW
Sleeping for 8.9 seconds, 2019-06-15 04:46:34
Page [[Template:Cite NSRW]] saved
Template:Twitter status/doc
Sleeping for 7.2 seconds, 2019-06-15 04:46:45
Page [[Template:Twitter status/doc]] saved
Template:Instagram post
Sleeping for 9.3 seconds, 2019-06-15 04:46:53
Page [[Template:Instagram post]] saved
Template:Instagram post/doc
Sleeping for 9.4 seconds, 2019-06-15 04:47:03
Page [[Template:Instagram post/doc]] saved
Template:Retrieved
Sleeping for 7.9 seconds, 2019-06-15 04:47:15
Page [[Template:Retrieved]] saved
Template:Retrieved/doc
Sleeping for 9.2 seconds, 2019-06-15 04:47:23
Page [[Template:Retrieved/doc]] saved
Template:Solar Saros series 119
Sleeping for 8.8 seconds, 2019-06-15 04:47:34
Page [[Template:Solar Saros series 119]] saved
Template:Solar Saros series 151
Sleeping for 9.2 seconds, 2019-06-15 04:47:44
Page [[Template:Solar Saros series 151]] saved
Template:Solar Saros series 156
Sleeping for 9.3 seconds, 2019-06-15 04:47:53
Page [[Template:Solar Saros series 156]] saved
Template:Solar Saros series 123
Sleeping for 9.3 seconds, 2019-06-15 04:48:03
Page [[Template:Solar Saros series 123]] saved
Template:Solar Saros series 153
Sleeping for 9.2 seconds, 2019-06-15 04:48:14
Page [[Template:Solar Saros series 153]] saved
Template:Solar Saros series 125
Sleeping for 9.2 seconds, 2019-06-15 04:48:24
Page [[Template:Solar Saros series 125]] saved
Template:Solar Saros series 148
Sleeping for 9.2 seconds, 2019-06-15 04:48:34
Page [[Template:Solar Saros series 148]] saved
Template:Solar Saros series 122
Sleeping for 9.2 seconds, 2019-06-15 04:48:44
Page [[Template:Solar Saros series 122]] saved
Template:Solar Saros series 117
Sleeping for 9.1 seconds, 2019-06-15 04:48:54
Page [[Template:Solar Saros series 117]] saved
Template:Solar Saros series 155
Sleeping for 8.4 seconds, 2019-06-15 04:49:04
Page [[Template:Solar Saros series 155]] saved
Template:Solar Saros series 150
Sleeping for 9.2 seconds, 2019-06-15 04:49:14
Page [[Template:Solar Saros series 150]] saved
Template:Solar Saros series 135
Sleeping for 9.2 seconds, 2019-06-15 04:49:24
Page [[Template:Solar Saros series 135]] saved
Sleeping for 9.3 seconds, 2019-06-15 04:49:34
Template:Solar Saros series 138
Page [[Template:Solar Saros series 138]] saved
Template:Solar Saros series 121
Sleeping for 9.2 seconds, 2019-06-15 04:49:44
Page [[Template:Solar Saros series 121]] saved
Template:Find sources/sandbox
Sleeping for 5.7 seconds, 2019-06-15 04:49:57
Page [[Template:Find sources/sandbox]] saved
Template:Chembox/sandbox
Sleeping for 8.4 seconds, 2019-06-15 04:50:04
Page [[Template:Chembox/sandbox]] saved
Template:Imdb title/testcases
Sleeping for 8.9 seconds, 2019-06-15 04:50:14
Page [[Template:Imdb title/testcases]] saved
Template:Metacritic film/doc
Sleeping for 7.2 seconds, 2019-06-15 04:50:26
Page [[Template:Metacritic film/doc]] saved
Template:Rotten Tomatoes/doc
Sleeping for 9.3 seconds, 2019-06-15 04:50:34
Page [[Template:Rotten Tomatoes/doc]] saved