ویکی‌پدیا:درخواست‌های ربات/تشخیص و افزودن میان‌ویکی

<syntaxhighlight lang="python">

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-

__version__ = '$Id: $'

import wikipedia as pywikibot import re, os, codecs, catlib, sys

faChars = u'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیًٌٍَُِّْٓيك' + u'۰۱۲۳۴۵۶۷۸۹' + u'‌' site = pywikibot.getSite('fa') enSite = pywikibot.getSite('en') titles = ['template1', 'template2', 'etc.']

class BasicBot:

   def run(self):
     for title in titles:
       title = 'Template:' + title
       if title == re.sub(u'[%s]' % faChars, , title):
         page = self.load(pywikibot.Page(site, title))
         pageDoc = self.load(pywikibot.Page(site, title+u'/توضیحات'))
         text = 
         textDoc = 
         text = page.get()
         textDoc = pageDoc.get()
         if text.find('[[en:') == -1:
           if textDoc.find('[[en:') == -1:
             if pywikibot.Page(enSite, title).exists():
               text = text.replace(u, u'\n\n' % title)
               if text.find('[[en:') == -1:
                 text += u'\n\n' % title
               self.add_iw(page, text)
   def add_iw(self, text, page):
     try:
       page.put(text, comment=u'ربات: تشخیص و افزودن میان‌ویکی انگلیسی', minorEdit=True, botflag=True)
     except pywikibot.LockedPage:
       pywikibot.output(u"Page %s is locked; skipping." % page.title(asLink=True))
     except pywikibot.EditConflict:
       pywikibot.output(u'Skipping %s because of edit conflict' % page.title())
     except pywikibot.SpamfilterError, error:
       pywikibot.output(u'Cannot change %s because of spam blacklist entry %s' % (page.title(), error.url))

def main():

   bot = BasicBot()
   bot.run()

if __name__ == "__main__":

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