أرابيكا:بوت/حماية القوالب كثيرة الإستخدام

هذه هي النسخة الحالية من هذه الصفحة، وقام بتعديلها عبود السكاف (نقاش | مساهمات) في 11:05، 18 أبريل 2020 (Bot: Replace deprecated <source> tag and "enclose" parameter، تغييرات تجميلية). العنوان الحالي (URL) هو وصلة دائمة لهذه النسخة.

(فرق) → نسخة أقدم | نسخة حالية (فرق) | نسخة أحدث ← (فرق)

بوت حماية القوالب يتم إستعماله لحماية عدد كبير من القوالب كثيرة الإستخدام.

لأستخراج قوالب كثيرة الإستخدام أستعمل هذا البوت

عليك وضع القوالب في ملف نصي بأسم 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 userlib
import login
import config,time
import wikipedia,codecs
wikipedia.config.put_throttle = 0
wikipedia.put_throttle.setDelay()    
def Page_Protection(pagename):
   site=wikipedia.getSite('ar')  
   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('ar')
    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'كلمة السر'# 
       usernames=u'حسابك الإداري'#
    #-------------------------------------------
    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()