پرش به محتوا

ویکی‌پدیا:درخواست‌های ربات/آمار ویرایشگران مقالات برگزیده

از ویکی‌پدیا، دانشنامهٔ آزاد
{{{نام ربات}}}
این کاربر یک ربات است
وظیفه(ها)استخراج نام کاربرهای مشارکت کننده در یک مقاله خاص و مشخص کردن درصد مشارکتشان
موافق محرومیت؟خیر
موافق خاموش‌شدن اضطراری؟بله
اجازه‌نامهCC-BY-SA 3.0
تست شده؟بله

نسخه دوم: در این نسخه حجم تغییرات مقاله و همچنین فهرست مقالات برگزیده قرار دارد.

موارد مورد نیاز[ویرایش]

  1. نام مقاله به صورت حروف درصدی
  2. تاریخ برگزیده شدن در صورتی که دکمه اینتر یا حرف y زده شود تاریخ امروز را به عنوان تاریخ برگزیدگی در نظر می‌گیرد.

نتیجه[ویرایش]

نتیجه جدولی است از نام ۱۰ کاربر که بیشترین ویرایش را در آن مقاله داشتند. و این جدول به صورت پیش فرض در کاربر:reza1615/test02 ذخیره می‌شود.

مثال[ویرایش]

ردیف کاربر درصد مشارکت تعداد ویرایش
۱ Elph % ۵۴ ۲۷۳
۲ AliReza % ۴ ۲۳
۳ Wiki66 % ۳ ۱۹
۴ Sasan Geranmehr % ۳ ۱۷
۵ Luckas-bot % ۲ ۱۳
۶ ایلیا 2010 % ۲ ۱۱
۷ مانفی % ۲ ۱۱
۸ Reza1615 % ۱ ۹
۹ همان % ۱ ۷
۱۰ Amirobot % ۱ ۷

آمار فوق مربوط به مقاله معمر قذافی تا تاریخ 02/11/2011 است.

<syntaxhighlight lang="python">

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-
  3. BY: رضا (User:reza1615 on fa.wikipedia)
  4. Distributed under the terms of the CC-BY-SA 3.0.

__version__ = '$Id: $'

import wikipedia, sys, pagegenerators import re, os, codecs, catlib, string from datetime import timedelta, datetime from collections import defaultdict

wikipedia.config.put_throttle = 0 wikipedia.put_throttle.setDelay() faSite = wikipedia.getSite('fa') enSite = wikipedia.getSite('en') txtTmp=' ' msg = u'ربات: درصد ويرايش کاربران در مقاله (کد)' savepage = u'کاربر:reza1615/test02' dateinput = u' '

def BotRun(page,text_history,dateinput):

   #maxdate='2011/11/02'
   maxdate=dateinput
   maxyear=int(maxdate.split('/')[0].strip())
   maxmonth=int(maxdate.split('/')[1].strip())
   maxday=int(maxdate.split('/')[2].strip())
   time,user,size=' ',' ',' '
   lastsize,count=0,0
   dictc,dicts,inverse={},{},{}
   text_history=text_history.replace('{| class="wikitable"',).replace('|}',).replace('! oldid || date/time || size || username || edit summary',).strip()
   table=text_history.split('|----')
   lent=len(table)-1
   for l in range(lent,0,-1) :
       line=table[l]
       count+=1
       item=line.split('||')
       time=item[1].strip()
       date=time.split('T')[0].strip()
       year=int(date.split('-')[0].strip())
       month=int(date.split('-')[1].strip())
       day=int(date.split('-')[2].strip())
       datenum=(year-2004)*365+(month)*30+day
       datenummax=(maxyear-2004)*365+(maxmonth)*30+maxday
       if datenummax>=datenum:
           user=item[3].strip()
           if user in dictc:
               dictc[user]=int(dictc[user])+1
           else:
               dictc[user]=1
   inverse = defaultdict(list)
   for k, v in dictc.items():
       inverse[int(v)].append( k )
   chart(inverse,count)

def chart(dictc,count):

   counter=0
   line=u" "
   charttop=u'{| class="wikitable sortable"\n!رديف!!کاربر!!درصد مشارکت!!تعداد ويرايش\n|-\n'
   chartdown=u'\n|}'
   for k in sorted(dictc, reverse=True):
           if counter>10:
                   break
           for i in range(0,len(dictc[k])):
               counter+=1
               if counter>10:
                   break                
               line+=u'|'+str(counter)+u'||[[کاربر:'+dictc[k][i]+u'|'+dictc[k][i]+u']]||'+str(k*۱۰۰/count)+u'?||'+str(k)+u'\n|-\n'
   chart=charttop+line.strip()+chartdown
   savepart(savepage,chart)
  1. ----------------------------------------------------------end of action that you want to do on pages---------------

def run(generator,dateinput):

       for page in generator: 
           try:
               if not page.canBeEdited():
                   wikipedia.output( u'Skipping locked page %s' % page.title() )
                   continue
               text_history = page.getVersionHistoryTable()#------------------------------geting pages content
           except wikipedia.NoPage:
               wikipedia.output( u'Page %s not found' % page.title() )
               continue
           except wikipedia.IsRedirectPage:#----------------------geting pages redirects contents
                pageRedirect = page.getRedirectTarget()
                text_history = pageRedirect.getVersionHistoryTable()
                wikipedia.output( u'Page %s was Redirect but edited!' %  pageRedirect )                
           except:
                continue
           #print text_history
           wikipedia.output(u'--------------------------------------------')
           BotRun(page,text_history,dateinput) 

def savepart(page, new_text):

    wikipedia.output(page)
    faSite = wikipedia.getSite('fa')
    savepage=wikipedia.Page(faSite,page)
    if new_text!=None and page!=None and new_text.find( u'#تغييرمسير')==-1 and  new_text.find( u'#redirect')==-1 and  new_text.find( u'#Redirect')==-1  and  new_text.find( u'#REDIRECT')==-1:
           try:
               savepage.put(new_text, msg, watchArticle = None, minorEdit = True)
           except wikipedia.EditConflict:
               wikipedia.output( u'Skipping %s because of edit conflict' % ( savepage.title() ) )
           except wikipedia.SpamfilterError,url:
               wikipedia.output( u'Cannot change %s because of blacklist entry %s' % ( savepage.title(),url ) )

def main():

   summary_commandline,template,gen = None,None,None
   exceptions,PageTitles,namespaces = [],[],[]
   autoText,autoTitle = False,False
   genFactory = pagegenerators.GeneratorFactory()
   wikipedia.setAction( msg )
   PageTitles = [wikipedia.input(u'Page Name:> ').decode('utf-8')]
   dateinput = wikipedia.input(u'Max-Date is Today, is it Ok?(y/n) defult is y :> ').decode('utf-8')
   if dateinput==u or dateinput==u'y' or dateinput==u'Yes' or dateinput==u'YES':
       dateinput=str(datetime.now()).split(' ')[0].replace('-','/').strip()
   if dateinput==u'n' or dateinput==u'N' or dateinput==u'NO' or dateinput==u'no' or dateinput==u'No':
       dateinput = wikipedia.input(u'Type Max-Date (2011/11/02):> ' ).decode('utf-8')
   if PageTitles:
       pages = [wikipedia.Page(faSite,PageTitle) for PageTitle in PageTitles]
       gen = iter( pages )
   if not gen:
       wikipedia.stopme()
       sys.exit()
   if namespaces != []:
       gen = pagegenerators.NamespaceFilterPageGenerator( gen,namespaces )
   preloadingGen = pagegenerators.PreloadingGenerator( gen,pageNumber = 60 )#---number of pages that you want load at same time
   run(preloadingGen,dateinput)

if __name__ == "__main__":

   try:
       main()
   finally:
       wikipedia.stopme()