ویکی‌پدیا:درخواست‌های ربات/ربات گروه مجوز دهندگان ربات

از ویکی‌پدیا، دانشنامهٔ آزاد

وظیفه این ربات بازبینی و اصلاح مقالات رباتیک و انتقال آنها به رده تائید شده است.

استفاده[ویرایش]

این ربات در دو وضعیت کار می‌کند

  • تائید اولیه مقالات که در این مرحله کارهای زیر انجام می‌گیرد
    • اصلاح نویسه‌های غیر استاندارد، اصلاح فاصله اضافی
    • در صورتی که مقاله میان‌ویکی یک‌طرفه نداشته باشد (میان‌ویکی ویکی‌فا در ویکی انگلیسی هم افزوده شده باشد) رده:بازبینی گمر را حذف می‌کند.
    • در غیر این صورت رده:بازبینی‌گمر میان‌ویکی نادرست را به مقاله می‌افزاید.

روش کار[ویرایش]

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

بعد از اجرای کد در حالت یک مواردی که میان‌ویکی یک‌طرفه دارند از رده رده:بازبینی گمر به رده:بازبینی‌گمر میان‌ویکی نادرست انتقال می‌یابند و مقالات موجود در این رده از نظر ویرایشی اصلاح می‌گردند که پس از اصلاح میان ویکی مقالات موجود در رده:بازبینی‌گمر میان‌ویکی نادرست این رده در حالت دو از مقالات زدوده می‌شود.

<syntaxhighlight lang="python">

#!/usr/bin/python

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

import wikipedia,query import pagegenerators,login import re, os, codecs, catlib wikipedia.config.put_throttle = 0 wikipedia.put_throttle.setDelay() faSite = wikipedia.getSite('fa') enSite = wikipedia.getSite('en') txtTmp=' ' faChrs = u'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیًٌٍَُِّْٓيك'

  1. enChrs=u'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'#می‌توان از [A-Za-z] استفاده کرد

faNums = u'۰۱۲۳۴۵۶۷۸۹' arNums = u'٠١٢٣٤٥٦٧٨٩' enNums = u'0123456789' msg=

def fixCsmtc(txt):

       # ZWNJ
       txt = re.sub(u'‌{2,}', u'‌', txt) # پشت‌سرهم
       txt = re.sub(u'\[\[([^\]\|]*?)‌]](%s+)' % faChrs, ur'\1‌\2', txt) # Piping
       txt = re.sub(u'‌(?![ئاآأإژزرذدوؤةبپتثجچحخسشصضطظعغفقکگلمنهیيًٌٍَُِّْٰٓٔ]|[\u0900-\u097F]|ֹ)', , txt) # در پس
       txt = re.sub(u'(?<![ئبپتثجچحخسشصضطظعغفقکگلمنهیيًٌٍَُِّْٰٓٔ]|[\u0900-\u097F]|f|ֹ)‌', , txt) # در پیش
       return txt
       

def englishdictionry( enlink ,firstsite,secondsite):

   try:
       enlink=unicode(str(enlink),'UTF-8').replace(u'',u'').replace(u'',u).replace(u'en:',u).replace(u'fa:',u)
   except:
       enlink=enlink.replace(u'',u'').replace(u'',u).replace(u'en:',u).replace(u'fa:',u)
   if enlink.find('#')!=-1:
       return False
   if enlink==u:
       return False    
   enlink=enlink.replace(u' ',u'_')
   site = wikipedia.getSite(firstsite)
   sitesecond= wikipedia.getSite(secondsite)
   params = {
       'action': 'query',
       'prop': 'langlinks',
       'titles': enlink,
       'redirects': 1,
       'lllimit':500,
   }
   try:
       categoryname = query.GetData(params,site)  
       for item in categoryname[u'query'][u'pages']:
           case=categoryname[u'query'][u'pages'][item][u'langlinks']
       for item in case:
           if item[u'lang']==secondsite:
               intersec=item[u'*']
               break
       result=intersec
       if result.find('#')!=-1:
           return False
       return result
   except: 
       return False

def interwikicheck(page):

           try:
               if not page.canBeEdited():
                   wikipedia.output( u'Skipping locked page %s' % page.title() )
                   return False
               text_fa = page.get()
           except wikipedia.NoPage:
               wikipedia.output( u'Page %s not found' % page.title() )
               return False
           except wikipedia.IsRedirectPage:
                pageRedirect = page.getRedirectTarget()
                text_fa = pageRedirect.get()
                wikipedia.output( u'Page %s was Redirect but edited!' %  pageRedirect )
           except:
                return False
                
           m = re.search(ur'\[\[([a-z]{2,3}|[a-z]{2,3}\-[a-z\-]{2,}|simple):.*?\]\]', text_fa)
           if m:
               lang=m.group(0).split(u':')[0].strip().replace(u'[[',u)
               if page.title()==englishdictionry(englishdictionry( page.title() ,'fa',lang),lang,'fa'):
                   return True
               else:
                   return u
           else:
               return True
               

def BotRun(page,text_fa,type,msg):

   if type==True:
       text_fa = re.sub(' {2,}', ' ', text_fa)
       text_fa=fixCsmtc(text_fa)
       if interwikicheck(page)==True:
               text_fa=text_fa.replace(u,u)
   else:
       text_fa = re.sub(' {2,}', ' ', text_fa)
       text_fa=fixCsmtc(text_fa)
       if interwikicheck(page)==True:
               text_fa=text_fa.replace(u,u)
       if interwikicheck(page)==u:
               text_fa=text_fa.replace(u'رده:بازبینی گمر',u'رده:بازبینی‌گمر میان‌ویکی نادرست')
   
   if text_fa!=None and page!=None and text_fa.find( u'#تغییرمسیر')==-1 and  text_fa.find( u'#ridirect')==-1 and  text_fa.find( u'#Ridirect')==-1:
           try:
               page.put( text_fa.strip(),msg ,watchArticle = None,minorEdit = True)
           except wikipedia.EditConflict:
               wikipedia.output( u'Skipping %s because of edit conflict' % ( page.title() ) )
           except wikipedia.SpamfilterError,url:
               wikipedia.output( u'Cannot change %s because of blacklist entry %s' % ( page.title(),url ) )    

def run(generator,type,msg):

       for page in generator: 
           if page.namespace()>0:
                continue
           try:
               if not page.canBeEdited():
                   wikipedia.output( u'Skipping locked page %s' % page.title() )
                   continue
               text_fa = page.get()#------------------------------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_fa = pageRedirect.get()
                wikipedia.output( u'Page %s was Redirect but edited!' %  pageRedirect )                
           except:
                continue
           wikipedia.output(page.title())
           new_text=BotRun(page,text_fa,type,msg)            

def main():

   summary_commandline,template,gen = None,None,None
   exceptions,PageTitles,namespaces = [],[],[]
   autoText,autoTitle = False,False
   genFactory = pagegenerators.GeneratorFactory()
   arg=False
   for arg in wikipedia.handleArgs():
           if arg.lower() == '-ok':
               msg = u'ربات:تائید گروه مجوز دهندگان ربات'
               gamarcat=u'رده:بازبینی‌گمر میان‌ویکی نادرست'
               type=True
   if arg==False:
               msg = u'ربات گمر:اصلاح و گزارش‌گیری از مقالات'
               gamarcat=u'رده:بازبینی گمر'
               type=False
   cat = catlib.Category( wikipedia.getSite('fa'),gamarcat)
   gent = pagegenerators.CategorizedPageGenerator(cat)    
   run(gent,type,msg)

if __name__ == "__main__":

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