跳至內容

使用者:Shizhao/vote/code

維基百科,自由的百科全書
# -*- coding: utf-8  -*-
import os, sys,wikipedia,config,userlib,query,time,datetime
site = wikipedia.getSite()
page = wikipedia.Page(site, u"User:Waihorace/Shizhao_7/detail")
templates = page.templatesWithParams()
an=0
en=0
ean=0
t=0
t1=0
t2a=0
t2b=0


def check(twp,user):
    autouser=False
    edit1=False
        
    p1=u''
    p2=u''
    #print userpage.registrationTime()
    #print userpage
    params = {
        'action': 'query',
        'list': 'usercontribs',
        'ucuser': user,
        'ucprop': ['timestamp'],
        'uclimit': 51,
        'ucdir': 'older',
        'ucstart': '2011-02-09T23:59:59Z'
    }
    params1 = {
        'action': 'query',
        'list': 'users',
        'ususers': user,
        'usprop': 'registration',
    }
    result1 = query.GetData(params1, site)
    result = query.GetData(params, site)
    # result['query']['usercontribs']>=50:
    print result1['query']['users'][0]['registration']
    s1 = datetime.datetime.strptime('2011-02-09T00:00:00Z', "%Y-%m-%dT%H:%M:%SZ")
    try:
        sr=datetime.datetime.strptime(result1['query']['users'][0]['registration'], "%Y-%m-%dT%H:%M:%SZ")
    except TypeError:
        sr=datetime.datetime.strptime('2004-01-01T00:00:00Z', "%Y-%m-%dT%H:%M:%SZ")
    print len(result['query']['usercontribs']), s1,sr,(s1-sr).days
    #自动确认用户
    if len(result['query']['usercontribs'])>=50 and (s1-sr).days>=7:
        print user +' is autouser'
        autouser=True
    else:
        print user +' NOT autouser'            
  #      an=an+1
            
    params2 = {
        'action': 'query',
        'list': 'usercontribs',
        'ucuser': user,
        'ucprop': ['timestamp'],
        'uclimit': 51,
        'ucdir': 'older',
        'ucstart': '2011-06-18T23:59:59Z',
        'ucend' : '2011-03-19T00:00:00Z',
        'ucnamespace': '0|1|4|5|6|7|8|9|10|11|12|13|14|15|100|101'
    }
    result2 = query.GetData(params2, site)
    
    if len(result2['query']['usercontribs']) >=1:
        edit1=True
        print user + ' edit +1'
    else:
        print user+' NOT edit' 
    #    en=en+1
    if autouser==True and edit1==True:
        print user+' is ok'
    else:
   #     ean=ean+1
        print user+ ' not OK!'
        p2=u' 未通过方案2'
        
        #print twp[1]

    tiaojian1=False
    tiaojian2a=False
    tiaojian2b=False
    #条件1
    params11 = {
        'action': 'query',
        'list': 'usercontribs',
        'ucuser': user,
        'ucprop': ['timestamp'],
        'uclimit': 101,
        'ucdir': 'older',
        'ucstart': '2011-06-11T23:59:59Z'
    }
    result11 = query.GetData(params11, site)
    params111 = {
        'action': 'query',
        'list': 'usercontribs',
        'ucuser': user,
        'ucprop': ['timestamp'],
        'uclimit': 101,
        'ucdir': 'older',
        'ucstart': '2011-06-18T23:59:59Z',
        'ucend' : '2010-12-19T00:00:00Z',
    }
    result111 = query.GetData(params111, site)        
    
    if len(result11['query']['usercontribs'])>=100 and len(result111['query']['usercontribs'])>=1:
        tiaojian1=True
        print user + 'is >100+1'
    else:
        print user + 'Not >100+1'
       # t1=t1+1
        #tiaojian2a
    params2a = {
        'action': 'query',
        'list': 'usercontribs',
        'ucuser': user,
        'ucprop': ['timestamp'],
        'uclimit': 3001,
        'ucdir': 'older',
        'ucstart': '2011-06-18T23:59:59Z',
    }
    result2a = query.GetData(params2a, site)
    if len(result2a['query']['usercontribs'])>=3000:
        tiaojian2a=True
        print user + 'is >3000'
    else:
        print user + 'Not >3000'
       # t2a=t2a+1  
         #tiaojian2b
    params2b = {
        'action': 'query',
        'list': 'usercontribs',
        'ucuser': user,
        'ucprop': ['timestamp'],
        'uclimit': 1501,
        'ucdir': 'older',
        'ucstart': '2011-06-18T23:59:59Z',
        'ucnamespace': '0'
    }
    result2b = query.GetData(params2b, site)
    if len(result2b['query']['usercontribs'])>=1500:
        tiaojian2b=True
        print user + 'is >1500'
    else:
        print user + 'Not >1500'
       # t2b=t2b+1                   
             
    if tiaojian1==True or tiaojian2a==True or tiaojian2b==True:
        print user+' is ok'
    else:
      #  t=t+1
        print user+ ' not OK!' 
        p1=u' 未通过方案一'
    p=p1+p2
    
    return p
x=0
xx=0
zhichi=[]
fandui=[]
zhichis=u''
fanduis=u''
for twp in templates:
    ttt=u''
    
    if twp[0]==u'/支持':
        user=twp[1][1]
        ttt=check(twp,user)    
        if ttt<>u'':
            vote=u'支持 '+twp[1][0]
            txt=u'* '+vote+u': {{user|'+user+u'}}'+ttt+u'\n'
            print txt
            zhichi.append(txt)   
  
    if twp[0]==u'/反对':
        user=twp[1][1]
        ttt=check(twp,user)    
        if ttt<>u'':
            vote=u'反对 '+twp[1][0]
            txt=u'* '+vote+u': {{user|'+user+u'}}'+ttt+u'\n'
            print txt
            fandui.append(txt)
zhichis = "".join(zhichi)
fanduis= "".join(fandui)
zhichis=zhichis+u''

test = wikipedia.Page(site, u"User:Shizhao/vote")
text=u'==支持==\n'+zhichis+u'==反对==\n'+fanduis
print text
test.put(text)