-
-
Save libkoi/c70af38c571ff91c6cbe3a42938b9271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pywikibot | |
from pywikibot.pagegenerators import SearchPageGenerator | |
import re | |
from tqdm import tqdm | |
site = pywikibot.Site('zh', 'wikipedia') | |
site.login() | |
gen0 = SearchPageGenerator("insource:/\{\{([Ss]ee ?[Aa]lso|[参參][看见見]|另[见見])\|\[\[[^:][^\]]+?\]\]\}\}/", site=site, namespaces=[0]) | |
gen1 = SearchPageGenerator("insource:/\{\{([Mm]ain( articles?)?|MAIN|主?([条條題]目|[页頁]面)?|AP|[Hh]urricane main)\|\[\[[^:][^\]]+?\]\]\}\}/", site=site, namespaces=[0]) | |
gen2 = SearchPageGenerator("insource:/\{\{([Ss]ee|[Dd]etails?|([Ff]urther|[Mm]ore)( information)?|相[关關][条條]目|更多[资資][料訊])\|\[\[[^:][^\]]+?\]\]\}\}/", site=site, namespaces=[0]) | |
count = 0 | |
for page in (gen0): | |
re0 = re.search(r"\{\{([Ss]ee ?[Aa]lso|[参參][看见見]|另[见見])\|\[\[[^:][^\]]+?\]\]\}\}", page.text, re.I) | |
print(f"{str(page.title())} -> {str(re0.group())}") | |
count += 1 | |
page.text = re.sub( | |
r"\{\{([Ss]ee ?[Aa]lso|[参參][看见見]|另[见見])\|\[\[([^:][^\]]+?)\|([^\]]+?)\]\]\}\}", | |
r"{{See also|\2{{!}}\3}}", page.text | |
) | |
page.text = re.sub( | |
r"\{\{([Ss]ee ?[Aa]lso|[参參][看见見]|另[见見])\|\[\[([^:][^\]]+?)\]\]\}\}", | |
r"{{See also|\2}}", page.text | |
) | |
page.save("机器人: 清理[[Template:See also]]模板参数") | |
print("======") | |
for page in (gen1): | |
re0 = re.search(r"\{\{([Mm]ain( articles?)?|MAIN|主?([条條題]目|[页頁]面)?|AP|[Hh]urricane main)\|\[\[[^:][^\]]+?\]\]\}\}", page.text, re.I) | |
print(f"{str(page.title())} -> {str(re0.group())}") | |
count += 1 | |
page.text = re.sub( | |
r"\{\{([Mm]ain( articles?)?|MAIN|主?([条條題]目|[页頁]面)?|AP|[Hh]urricane main)\|\[\[([^:][^\]]+?)\|([^\]]+?)\]\]\}\}", | |
r"{{Main|\4{{{!}}\5}}", page.text | |
) | |
page.text = re.sub( | |
r"\{\{([Mm]ain( articles?)?|MAIN|主?([条條題]目|[页頁]面)?|AP|[Hh]urricane main)\|\[\[([^:][^\]]+?)\]\]\}\}", | |
r"{{Main|\4}}", page.text | |
) | |
page.save("机器人: 清理[[Template:Main]]模板参数") | |
print("======") | |
for page in (gen2): | |
re0 = re.search(r"\{\{([Ss]ee|[Dd]etails?|([Ff]urther|[Mm]ore)( information)?|相[关關][条條]目|更多[资資][料訊])\|\[\[[^:][^\]]+?\]\]\}\}", page.text, re.I) | |
print(f"{str(page.title())} -> {str(re0.group())}") | |
count += 1 | |
page.text = re.sub( | |
r"\{\{([Ss]ee|[Dd]etails?|([Ff]urther|[Mm]ore)( information)?|相[关關][条條]目|更多[资資][料訊])\|\[\[([^:][^\]]+?)\|([^\]]+?)\]\]\}\}", | |
r"{{Further|\4{{!}}\5}}", page.text | |
) | |
page.text = re.sub( | |
r"\{\{([Ss]ee|[Dd]etails?|([Ff]urther|[Mm]ore)( information)?|相[关關][条條]目|更多[资資][料訊])\|\[\[([^:][^\]]+?)\]\]\}\}", | |
r"{{Further|\4}}", page.text | |
) | |
page.save("机器人: 清理[[Template:Further]]模板参数") | |
print("======") | |
print("######") | |
print(f"Fixed {count} articles") | |
print("######") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment