User:Huhu9001Bot/00:46, 8 March 2023 (UTC)

From Wiktionary, the free dictionary
Jump to navigation Jump to search
import pywikibot
import pywikibot.pagegenerators
import re

pgf = pywikibot.pagegenerators.GeneratorFactory(site = pywikibot.Site('en','wiktionary'))
pgf.handle_args([
    '-transcludes:Template:tracking/ja-headword/shin',
    r'-titleregex:[^ぁ-ゖァ-ヶ]',
])
pg = pgf.getCombinedGenerator()

def funRepl(m):
    print(m.group(2))
    return m.group(1)[:-1] + m.group(3)

for p in pg:
    print(p)
    p.text = re.sub(r'({{ja-(?:noun|verb|verb-suru|adj|pos|phrase)\|(?:[^{}]*\|)?)(shin=[^{|}]+?)((?:\|[^{}]*)?}})', funRepl, p.text)
    p.save('remove |shin=')