用戶討論:Air7538/沙盒03
用於Template:Breadcrumb2。Air7538#Sign 2020年11月29日 (日) 05:04 (UTC)
import pywikibot,time,re
from pywikibot import pagegenerators
from datetime import datetime
site = pywikibot.Site('zh', 'wikipedia')
cat = pywikibot.Category(site,'Category:已逝世超過一個月的人物')
gen = pagegenerators.CategorizedPageGenerator(cat)
localday = time.strftime("%Y-%m-%d", time.localtime())
localday = datetime.strptime(localday,'%Y-%m-%d')
pagetext = ""
for page in gen:
re0 = re.search('\{\{recent death\|time=\d+-\d+-\d+\}\}',page.text,re.I)
if re0 == None:continue
re0 = re0.group()
textday = datetime.strptime(re.search('\d+-\d+-\d+',re0).group(),'%Y-%m-%d')
pagetext += "[[" + page.title() + "]] - " + str(localday - textday) + "\n\n"
pagetext += "当前日期:" + str(localday) + "\n "
page = pywikibot.Page(site, "User:Air7538/沙盒03")
page.text = pagetext
print(page.text)
page.save()