ویکی‌پدیا:درخواست‌های ربات/محافظت صفحه‌ها بر پایه فهرست

این ربات برای محافظت فهرستی از صفحه‌ها که در فایل most_used_pages.txt ذخیره شده باشند کاربرد دارد.

الگوهای پر کاربرد ویرایش

برای یافتن فهرست الگوهای پرکاربردی که محافظت نشده‌اند از این ربات استفاده نمائید.

#!/usr/bin/python
# -*- coding: utf-8  -*-
#
# Reza(User:reza1615), 2012
#
# Distributed under the terms of the CC-BY-SA 3.0 .
# it is only runs as sysop
import userlib2
import login
import config,time
import wikipedia,codecs
wikipedia.config.put_throttle = 0
wikipedia.put_throttle.setDelay()    
def Page_Protection(pagename):
   site=wikipedia.getSite('fa')  
   reasons=u'ربات:محافظت الگوهای پرکاربرد و حساس'
   Page_name=wikipedia.Page(site,pagename)    
   #-----------log in as sysop--------------- 
   Page_name.protect(editcreate='sysop', move='sysop', unprotect=False,
                reason=reasons, editcreate_duration='infinite',
                move_duration = 'infinite', cascading = False, prompt = True, throttle = True)
   wikipedia.output(u'\03{lightgreen}'+pagename+u' now is Protected\03{default}')    
 
def main():
    site=wikipedia.getSite('fa')
    try:
        text = codecs.open(u'/home/youracount/pywikipedia/most_used_pages.txt','r' ,'utf8')#youacount is your acount name in toolserver
    except:
        text = codecs.open(u'most_used_pages.txt','r' ,'utf8')    
    text = text.read()
    text=text.replace(u'\r',u'')
    pages=text.split(u'\n')
    try:
       password_fa = open(wikipedia.config.datafilepath(config.password_file), 'r')
       password_fa=password_fa.read().replace('"','').strip()
       passwords=password_fa.split('(')[1].split(',')[1].split(')')[0].strip()
       usernames=password_fa.split('(')[1].split(',')[0].split(')')[0].strip()
    except:
       passwords=u'yourpass'# 
       usernames=u'yourusername'#
    #-------------------------------------------
    botlog=login.LoginManager(password=passwords,username=usernames,site=site,sysop=True)
    botlog.login()
    
    for page in pages:
        page=page.replace(u'[[:',u'').replace(u']]',u'').replace(u'[[',u'').strip()
        try:
            Page_Protection(page)
            time.sleep(1)    
        except:
            wikipedia.output(u'\03{lightred}'+page + u' is not valied template\03{default}')    
if __name__ == '__main__':
        main()