Skip to content

Instantly share code, notes, and snippets.

@shizhao
Last active September 1, 2016 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shizhao/372e7ac34593ee7f1926be12af029679 to your computer and use it in GitHub Desktop.
Save shizhao/372e7ac34593ee7f1926be12af029679 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
from pywikibot import config
import pywikibot
import pywikibot.data.api
site = pywikibot.Site()
#获取新页面(实际是从最近更改获取的,暂时没有新页面的API)
pages = site.newpages(user=None, returndict=True,
start=pywikibot.Timestamp.utcnow(), end=pywikibot.Timestamp.utcnow()-datetime.timedelta(days=5), reverse=False, showBot=False,
showRedirects=False, excludeuser=None,
showPatrolled=None, namespaces=0, step=None, total=5000)
n=0
dyks=[]
for page in pages:
#print page
#p=pywikibot.Page(site, page[1][u'title'])
#x= pywikibot.data.api.PropertyGenerator('info', titles=page[1][u'title'])
title=page[1][u'title']
#获取单个页面的大小数据
for pageinfo in pywikibot.data.api.PropertyGenerator('info', titles=title):
#个别情况下length key找不到,可能是API不稳定或者请求的时候页面被删除
try:
length = pageinfo[u'length']
#超过3000字节大小的条目
if length >3000:
page2 =page[0]
#print page2, page[1][u'newlen'], page[1][u'user'], title
#print page2.toggleTalkPage()
talkpage=page2.toggleTalkPage()
username = page[1][u'user']
date=page[1][u'timestamp']
ndyk=u''
#print page2.templates()
#挂有条目消息框的页面不算
if pywikibot.Page(site,u'Template:Ambox') in page2.templates():
pywikibot.output(u'Found in [[%s]](%s byte): "{{Ambox}}" in content, nothing necessary' % (title, length))
#已经提名的条目
elif pywikibot.Page(site,u'Template:DYK Invite') in talkpage.templates():
ndyk=u'{{NDYK|title='+title+u'|length='+str(length)+u'|user='+username+u'|date='+date+u'|flag=invite}}\n'
pywikibot.output(u'Fond a DYK: [[%s]]. length is %s byte. Have invite.' % (title, length))
n = n+1
#已经通过的条目
elif pywikibot.Page(site,u'Template:DYKtalk') in talkpage.templates():
ndyk=u'{{NDYK|title='+title+u'|length='+str(length)+u'|user='+username+u'|date='+date+u'|flag=dyk}}\n'
pywikibot.output(u'Fond a DYK: [[%s]]. length is %s byte. Have invite have DYK.' % (title, length))
n = n+1
#可能没有参考文献的条目
elif (pywikibot.Page(site,u'模块:Citation/CS1') not in page2.templates()) and (pywikibot.Page(site,u'Template:Reflist') not in page2.templates()):
ndyk=u'{{NDYK|title='+title+u'|length='+str(length)+u'|user='+username+u'|date='+date+u'|ref=no}}\n'
pywikibot.output(u'Fond a DYK: [[%s]]. length is %s byte. May no sources.' % (title, length))
n = n+1
else:
ndyk=u'{{NDYK|title='+title+u'|length='+str(length)+u'|user='+username+u'|date='+date+u'}}\n'
pywikibot.output(u'Fond a DYK: [[%s]]. length is %s byte' % (title, length))
n = n+1
#print ndyk
dyks.append(ndyk)
except:
print 'ERROR'
dykpage=pywikibot.Page(site,u'User:Sz-iwbot/DYK')
dykpagecontent=''.join(dyks)
h=u'最近5天创建的条目中共有%s个条目“可能”符合[[WP:DYKC|DYKC]]的条件。本列表最后更新于~~~~~\n' %str(n)
h=h+u'{|class="wikitable"\n!条目||长度||创建者||创建日期\n'
dykpagecontent=h+dykpagecontent
dykpage.put(dykpagecontent,u'BOT找到%s个条目' %str(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment