پرش به محتوا

ویکی‌پدیا:درخواست‌های ربات/ربات مترجم/ویرایش 0

از ویکی‌پدیا، دانشنامهٔ آزاد
#!/usr/bin/python
# -*- coding: utf-8  -*-
#
# Reza(User:reza1615), 2011
#
# Distributed under the terms of the CC-BY-SA 3.0 .
import catlib
import pagegenerators
import wikipedia,add_text2
self=''
def main():
    def __init__( self,generator,always,summary = None ):
        self.generator = generator
        self.always = always
        self.dry = False
        self.summary = summary
    site = wikipedia.getSite()
    cat = catlib.Category(site,'Category:2009 Convert unit subtemplates')
    gen = pagegenerators.CategorizedPageGenerator(cat)
    for pageout in gen:
  #Do something with the page object, for example:
        text = pageout.get()
# Define the main function
        pagename = u'ویکی‌پدیا:صفحه تمرین'
        pageinput = wikipedia.Page(site, pagename)
        wikipedia.output(u"Loading %s..." % pagename) # Please, see the "u" before the text
        try:
            text = pageout.get(force = False, get_redirect=False, throttle = True, sysop = False,change_edit_time = True) # text = page.get() <-- is the same
        except wikipedia.NoPage: # First except, prevent empty pages
            text = ''
        except wikipedia.IsRedirectPage: # second except, prevent redirect
            wikipedia.output(u'%s is a redirect!' % pagename)
            exit()# wikipedia.stopme() is in the finally, we don't need to use it twice, exit() will only close the script
        except wikipedia.Error: # third exception, take the problem and print
            wikipedia.output(u"Some Error, skipping..")
            exit()
        text = text + '\n'
        comment=u'ربات'
        add_text2.add_text( pageinput,text,None,None)
        #pageinput.put(text, comment=u'ربات', watchArticle = None, minorEdit = True)  # page.put(newtext, 'Bot: Test') <-- is the same
 
if __name__ == '__main__':
    try:
        main()
    finally:
        wikipedia.stopme()