# -*- coding: utf-8 -*-
import os
import re

import pywikibot


os.environ['PYWIKIBOT2_DIR'] = os.path.dirname(os.path.realpath(__file__))
os.environ['TZ'] = 'UTC'

site = pywikibot.Site()
site.login()

summary = '機器人：[[Special:PermaLink/53078964#優良條目和典范条目子頁面繁簡皆有的問題|統一子頁面繁簡]]'

with open('list.csv', 'r') as f:
    for title in f:
        oldtitle = title.strip()
        page = pywikibot.Page(site, oldtitle)
        if not page.exists():
            print('{} not found'.format(oldtitle))
            continue

        newtitle = oldtitle.replace('Wikipedia:優良條目', 'Wikipedia:优良条目')
        print('move', oldtitle, 'to', newtitle)

        page.move(newtitle, reason=summary, movetalk=True, noredirect=True)

        for backlink in page.embeddedin():
            if re.search(r'^Wikipedia:优良条目/\d+年\d+月\d+日$', backlink.title()):
                print(backlink.title())
                text = backlink.text
                text = text.replace('{{Wikipedia:優良條目/', '{{Wikipedia:优良条目/')

                pywikibot.showDiff(backlink.text, text)

                backlink.text = text
                print(summary)
                backlink.save(summary=summary, minor=True)

@@ -923,31 +923,147 @@
     
-text = text.replace(
+if re.search(r'Wikipedia:%E5%84%AA%E8%89%AF%E6%A2%9D%E7%9B%AE/s', text):%0A                    print('skip')%0A                    continue%0A                text = re.sub(r
 '%7B%7B
+(
 Wiki
@@ -1063,24 +1063,30 @@
 %7B%7B(Wikipedia
+%7C%E7%BB%B4%E5%9F%BA%E7%99%BE%E7%A7%91)
 :%E5%84%AA%E8%89%AF%E6%A2%9D%E7%9B%AE/', '%7B%7B
@@ -1101,16 +1101,22 @@
 a:%E4%BC%98%E8%89%AF%E6%9D%A1%E7%9B%AE/'
+, text
 )%0A%0A     

Fix regex, ignore soma pages