ویکی‌پدیا:درخواست‌های ربات/حذف ناوباکس‌های ناموجود با اعضای زیاد از مقالات

<syntaxhighlight lang="python">

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-
  3. Reza(User:reza1615), 2013
  4. Distributed under the terms of the CC-BY-SA 3.0 .

import wikipedia,config,re wikipedia.config.put_throttle = 0 wikipedia.put_throttle.setDelay()

def getlinks(enlink):

       site = wikipedia.getSite('fa')
       page = wikipedia.Page(site,enlink)
       linktos=page.getReferences()
       for page in linktos:    
                   text=page.get()
                   wikipedia.output(u'------------------------------ ')
                   wikipedia.output(u'checking '+page.title()+u' .....')    
                   enlink=enlink.strip()
                   falink=enlink.replace(u'الگو:',u).strip()[:-2]
                   if text.find(falink)!=-1:
                       text=text.replace(u'{{ ',u'{{').replace(u' {{',u'الگو:').replace(u'',u'}}').replace(u'}}',u'}}').replace(u'{{الگو:',u'{{').replace(u'\r',u)
                       text2=text
                       text = re.sub(ur"\{\{"+falink+ur"(\|.*?|.*?|)\}\}(\s|\n|)",ur"",text)
                       if text!=text2:
                           text = re.sub('[\r\n]{3,}', "\n\n",text)
                           try:
                               page.put(text,u'ربات:حذف الگوی ناموجود دارای اعضای زیاد (وظیفه ۱۴)')
                               wikipedia.output(u'\03{lightgreen}The page '+page.title()+u' removed الگو:'+falink+u'\03{default}')
                           except:
                               wikipedia.output(u'\03{lightred}The page '+page.title()+u' could not replaced so it passed\03{default}')
                               continue
                   else:
                        wikipedia.output(u'\03{lightred}could not find andy link\03{default}')        

results=(u'الگو:شهرستان زاهدان‎‏', u'الگو:شهرهای ایالت اکلاهما‎‏', u'الگو:شهرستان رضوان‌شهر‎‏') for enlink in results:

   a=getlinks(enlink)