#!/usr/bin/python
# -*- coding: utf-8 -*-
import pywikibot
import pywikibot.data.mysql as wikimysql
import time
site = pywikibot.Site()
#--------------------------------
page = pywikibot.Page(site, "Wikipedia:資料庫報告/与维基共享资源同名的文件")
commons_site = pywikibot.Site('commons', 'commons')
images = wikimysql.mysql_query(query="SELECT img_name FROM image",dbname='zhwiki_p')
text = '更新于~~~~~\n'
for image in images:
image_title = image[0].decode()
image_in_commons = pywikibot.Page(commons_site, image_title, ns=6)
if image_in_commons.exists():
line = '[[:File:%s]]同名于[[:commons:%s]]' % (image_title, image_in_commons.title())
print(line)
text = text + "\n* " + line +"\n"
page.text = text
page.save('更新于'+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print('END')