<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import re <EOL> import wikipedia as pywikibot <EOL> import pagegenerators <EOL> from pywikibot import i18n <EOL> docuReplacements = { <EOL> '<STR_LIT>' : pagegenerators . parameterHelp <EOL> } <EOL> class BasicBot ( object ) : <EOL> def __init__ ( self , generator , summary ) : <EOL> """<STR_LIT>""" <EOL> self . generator = generator <EOL> self . site = pywikibot . getSite ( code = pywikibot . default_code ) <EOL> if summary : <EOL> self . summary = summary <EOL> else : <EOL> self . summary = i18n . twtranslate ( self . site , '<STR_LIT>' ) <EOL> def run ( self ) : <EOL> for page in self . generator : <EOL> self . treat ( page ) <EOL> def treat ( self , page ) : <EOL> """<STR_LIT>""" <EOL> text = self . load ( page ) <EOL> if not text : <EOL> return <EOL> text = '<STR_LIT>' + text <EOL> if not self . save ( text , page , self . summary ) : <EOL> pywikibot . output ( u'<STR_LIT>' % page . title ( asLink = True ) ) <EOL> def load ( self , page ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> text = page . get ( ) <EOL> except pywikibot . NoPage : <EOL> pywikibot . output ( u"<STR_LIT>" <EOL> % page . title ( asLink = True ) ) <EOL> except pywikibot . IsRedirectPage : <EOL> pywikibot . output ( u"<STR_LIT>" <EOL> % page . title ( asLink = True ) ) <EOL> else : <EOL> return text <EOL> return None <EOL> def save ( self , text , page , comment = None , ** kwargs ) : <EOL> if text != page . get ( ) : <EOL> pywikibot . output ( u"<STR_LIT>" <EOL> % page . title ( ) ) <EOL> pywikibot . showDiff ( page . get ( ) , text ) <EOL> pywikibot . output ( u'<STR_LIT>' % comment ) <EOL> choice = pywikibot . inputChoice ( <EOL> u'<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , [ '<STR_LIT:y>' , '<STR_LIT:N>' ] , '<STR_LIT:N>' ) <EOL> if choice == '<STR_LIT:y>' : <EOL> try : <EOL> page . put ( text , comment = comment or self . comment , ** kwargs ) <EOL> except pywikibot . LockedPage : <EOL> pywikibot . output ( u"<STR_LIT>" <EOL> % page . title ( asLink = True ) ) <EOL> except pywikibot . EditConflict : <EOL> pywikibot . output ( <EOL> u'<STR_LIT>' <EOL> % ( page . title ( ) ) ) <EOL> except pywikibot . SpamfilterError , error : <EOL> pywikibot . output ( <EOL> u'<STR_LIT>' <EOL> % ( page . title ( ) , error . url ) ) <EOL> else : <EOL> return True <EOL> return False <EOL> class AutoBasicBot ( BasicBot ) : <EOL> _REGEX_eol = re . compile ( u'<STR_LIT:\n>' ) <EOL> def __init__ ( self ) : <EOL> BasicBot . __init__ ( self , None , None ) <EOL> def save ( self , page , text , comment = None , ** kwargs ) : <EOL> pywikibot . output ( u'<STR_LIT>' <EOL> % page . title ( asLink = True ) ) <EOL> comment_output = comment or pywikibot . action <EOL> pywikibot . output ( u'<STR_LIT>' <EOL> % comment_output ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> try : <EOL> page . put ( text , comment = comment , ** kwargs ) <EOL> except pywikibot . LockedPage : <EOL> pywikibot . output ( <EOL> u"<STR_LIT>" <EOL> % page . title ( asLink = True ) ) <EOL> except pywikibot . EditConflict : <EOL> pywikibot . output ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' % ( page . title ( ) ) ) <EOL> except pywikibot . SpamfilterError , error : <EOL> pywikibot . output ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' % ( page . title ( ) , error . url ) ) <EOL> else : <EOL> return True <EOL> return False <EOL> def append ( self , page , text , comment = None , section = None , ** kwargs ) : <EOL> if section : <EOL> pywikibot . output ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' % ( page . title ( asLink = True ) , section ) ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> try : <EOL> page . append ( text , comment = comment , section = section , <EOL> ** kwargs ) <EOL> except pywikibot . PageNotSaved , error : <EOL> pywikibot . output ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' % ( page . title ( ) , error ) ) <EOL> else : <EOL> return True <EOL> else : <EOL> content = self . load ( page ) <EOL> if not content : <EOL> content = u'<STR_LIT>' <EOL> content += u'<STR_LIT>' <EOL> content += text <EOL> return self . save ( page , content , comment = comment , ** kwargs ) <EOL> def loadTemplates ( self , page , template , default = { } ) : <EOL> """<STR_LIT>""" <EOL> self . _content = self . load ( page ) <EOL> templates = [ ] <EOL> if not self . _content : <EOL> return templates <EOL> for tmpl in pywikibot . extract_templates_and_params ( self . _content ) : <EOL> if tmpl [ <NUM_LIT:0> ] == template : <EOL> param_default = { } <EOL> param_default . update ( default ) <EOL> param_default . update ( tmpl [ <NUM_LIT:1> ] ) <EOL> templates . append ( param_default ) <EOL> return templates <EOL> def loadJobQueue ( self , page , queue_security , reset = True ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> actual = page . getVersionHistory ( revCount = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> except : <EOL> pass <EOL> secure = False <EOL> for item in queue_security [ <NUM_LIT:0> ] : <EOL> secure = secure or ( actual [ <NUM_LIT:2> ] == item ) <EOL> secure = secure and ( actual [ <NUM_LIT:3> ] == queue_security [ <NUM_LIT:1> ] ) <EOL> if not secure : <EOL> return [ ] <EOL> data = self . _REGEX_eol . split ( page . get ( ) ) <EOL> if reset : <EOL> pywikibot . output ( u'<STR_LIT>' ) <EOL> pywikibot . setAction ( u'<STR_LIT>' ) <EOL> page . put ( u'<STR_LIT>' , minorEdit = True ) <EOL> queue = [ ] <EOL> for line in data : <EOL> queue . append ( line [ <NUM_LIT:1> : ] . strip ( ) ) <EOL> return queue <EOL> def main ( ) : <EOL> genFactory = pagegenerators . GeneratorFactory ( ) <EOL> gen = None <EOL> pageTitleParts = [ ] <EOL> editSummary = '<STR_LIT>' <EOL> for arg in pywikibot . handleArgs ( ) : <EOL> if arg . startswith ( '<STR_LIT>' ) : <EOL> editSummary = arg [ <NUM_LIT:9> : ] <EOL> else : <EOL> if not genFactory . handleArg ( arg ) : <EOL> pageTitleParts . append ( arg ) <EOL> if pageTitleParts != [ ] : <EOL> pageTitle = '<STR_LIT:U+0020>' . join ( pageTitleParts ) <EOL> page = pywikibot . Page ( pywikibot . getSite ( ) , pageTitle ) <EOL> gen = iter ( [ page ] ) <EOL> if not gen : <EOL> gen = genFactory . getCombinedGenerator ( ) <EOL> if gen : <EOL> gen = pagegenerators . PreloadingGenerator ( gen ) <EOL> bot = BasicBot ( gen , editSummary ) <EOL> bot . run ( ) <EOL> else : <EOL> pywikibot . showHelp ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> main ( ) <EOL> finally : <EOL> pywikibot . stopme ( ) </s>
