<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import wikipedia as pywikibot <EOL> from pywikibot import i18n <EOL> import pagegenerators <EOL> import query <EOL> import datetime <EOL> import time <EOL> import os <EOL> import re <EOL> import locale <EOL> import traceback <EOL> ZERO = datetime . timedelta ( <NUM_LIT:0> ) <EOL> Site = pywikibot . getSite ( ) <EOL> try : <EOL> import hashlib <EOL> new_hash = hashlib . md5 <EOL> except ImportError : <EOL> import md5 <EOL> new_hash = md5 . md5 <EOL> language = Site . language ( ) <EOL> def message ( key , lang = Site . language ( ) ) : <EOL> return i18n . twtranslate ( lang , key ) <EOL> class MalformedConfigError ( pywikibot . Error ) : <EOL> """<STR_LIT>""" <EOL> class MissingConfigError ( pywikibot . Error ) : <EOL> """<STR_LIT>""" <EOL> class AlgorithmError ( MalformedConfigError ) : <EOL> """<STR_LIT>""" <EOL> class ArchiveSecurityError ( pywikibot . Error ) : <EOL> """<STR_LIT>""" <EOL> def str2time ( str ) : <EOL> """<STR_LIT>""" <EOL> if str [ - <NUM_LIT:1> ] == '<STR_LIT:d>' : <EOL> return datetime . timedelta ( days = int ( str [ : - <NUM_LIT:1> ] ) ) <EOL> elif str [ - <NUM_LIT:1> ] == '<STR_LIT:h>' : <EOL> return datetime . timedelta ( hours = int ( str [ : - <NUM_LIT:1> ] ) ) <EOL> else : <EOL> return datetime . timedelta ( seconds = int ( str ) ) <EOL> def str2size ( str ) : <EOL> """<STR_LIT>""" <EOL> if str [ - <NUM_LIT:1> ] . isdigit ( ) : <EOL> return ( int ( str ) , '<STR_LIT:B>' ) <EOL> elif str [ - <NUM_LIT:1> ] in [ '<STR_LIT>' , '<STR_LIT:k>' ] : <EOL> return ( int ( str [ : - <NUM_LIT:1> ] ) * <NUM_LIT> , '<STR_LIT:B>' ) <EOL> elif str [ - <NUM_LIT:1> ] == '<STR_LIT:M>' : <EOL> return ( int ( str [ : - <NUM_LIT:1> ] ) * <NUM_LIT> * <NUM_LIT> , '<STR_LIT:B>' ) <EOL> elif str [ - <NUM_LIT:1> ] == '<STR_LIT:T>' : <EOL> return ( int ( str [ : - <NUM_LIT:1> ] ) , '<STR_LIT:T>' ) <EOL> else : <EOL> return ( int ( str [ : - <NUM_LIT:1> ] ) * <NUM_LIT> , '<STR_LIT:B>' ) <EOL> def generateTransclusions ( Site , template , namespaces = [ ] ) : <EOL> pywikibot . output ( u'<STR_LIT>' ) <EOL> transclusionPage = pywikibot . Page ( Site , template , defaultNamespace = <NUM_LIT:10> ) <EOL> gen = pagegenerators . ReferringPageGenerator ( transclusionPage , <EOL> onlyTemplateInclusion = True ) <EOL> if namespaces : <EOL> gen = pagegenerators . NamespaceFilterPageGenerator ( gen , namespaces , Site ) <EOL> for page in gen : <EOL> yield page <EOL> class Months ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , site = None ) : <EOL> if site is None : <EOL> self . site = pywikibot . getSite ( ) <EOL> else : <EOL> self . site = site <EOL> @ classmethod <EOL> def queryMonths ( self ) : <EOL> months_long = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> months_short = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> params = { <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:|>' . join ( months_long ) + '<STR_LIT:|>' + '<STR_LIT:|>' . join ( months_short ) , <EOL> '<STR_LIT>' : self . site . lang , <EOL> } <EOL> monthsDict = query . GetData ( params ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> monthNum2origNames = dict ( ( i , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) for i in range ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> origNames2monthNum = dict ( ) <EOL> for el in monthsDict : <EOL> orig , eng = el [ '<STR_LIT:*>' ] , el [ '<STR_LIT:name>' ] <EOL> try : <EOL> month_num = months_long . index ( eng ) + <NUM_LIT:1> <EOL> monthNum2origNames [ month_num ] [ '<STR_LIT>' ] = orig <EOL> except ValueError : <EOL> month_num = months_short . index ( eng ) + <NUM_LIT:1> <EOL> monthNum2origNames [ month_num ] [ '<STR_LIT>' ] = orig <EOL> origNames2monthNum [ orig ] = month_num <EOL> return monthNum2origNames , origNames2monthNum <EOL> @ classmethod <EOL> def updateMonths ( self , site = None ) : <EOL> if site is None : <EOL> self . site = pywikibot . getSite ( ) <EOL> else : <EOL> self . site = site <EOL> self . monthsDicts = self . queryMonths ( ) <EOL> class tzoneUTC ( datetime . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> def utcoffset ( self , dt ) : <EOL> return ZERO <EOL> def tzname ( self , dt ) : <EOL> return '<STR_LIT>' <EOL> def dst ( self , dt ) : <EOL> return ZERO <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . __class__ . __name__ <EOL> class tzoneFixedOffset ( datetime . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , offset , name ) : <EOL> self . __offset = datetime . timedelta ( minutes = offset ) <EOL> self . __name = name <EOL> def utcoffset ( self , dt ) : <EOL> return self . __offset <EOL> def tzname ( self , dt ) : <EOL> return self . __name <EOL> def dst ( self , dt ) : <EOL> return ZERO <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . __class__ . __name__ , <EOL> self . __offset . days * <NUM_LIT> + self . __offset . seconds , <EOL> self . __name <EOL> ) <EOL> class TimeStripper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . monthNum2origNames , self . origNames2monthNum = Months . monthsDicts <EOL> self . site = Months . site <EOL> self . groups = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT:time>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> timeR = r'<STR_LIT>' <EOL> timeznR = r'<STR_LIT>' <EOL> yearR = r'<STR_LIT>' <EOL> monthR = ur '<STR_LIT>' % ( u'<STR_LIT:|>' . join ( self . origNames2monthNum ) ) <EOL> dayR = r'<STR_LIT>' <EOL> self . ptimeR = re . compile ( timeR ) <EOL> self . timeznR = re . compile ( timeznR ) <EOL> self . yearR = re . compile ( yearR ) <EOL> self . pmonthR = re . compile ( monthR , re . U ) <EOL> self . pdayR = re . compile ( dayR ) <EOL> self . patterns = [ <EOL> self . ptimeR , <EOL> self . timeznR , <EOL> self . yearR , <EOL> self . pmonthR , <EOL> self . pdayR , <EOL> ] <EOL> def findmarker ( self , text , base = u'<STR_LIT>' , delta = '<STR_LIT:@>' ) : <EOL> while base in text : <EOL> base += delta <EOL> return base <EOL> def last_match_and_replace ( self , txt , pat ) : <EOL> """<STR_LIT>""" <EOL> m = None <EOL> for m in pat . finditer ( txt ) : <EOL> pass <EOL> if m : <EOL> marker = self . findmarker ( txt ) <EOL> txt = pat . sub ( marker , txt ) <EOL> return ( txt , m . groupdict ( ) ) <EOL> else : <EOL> return ( txt , None ) <EOL> def timestripper ( self , line ) : <EOL> """<STR_LIT>""" <EOL> _line = line <EOL> dateDict = dict ( ) <EOL> for pat in self . patterns : <EOL> line , matchDict = self . last_match_and_replace ( line , pat ) <EOL> if matchDict : <EOL> dateDict . update ( matchDict ) <EOL> if all ( g in dateDict for g in self . groups ) : <EOL> del dateDict [ '<STR_LIT:time>' ] <EOL> try : <EOL> dateDict [ '<STR_LIT>' ] = self . origNames2monthNum [ dateDict [ '<STR_LIT>' ] ] <EOL> except KeyError : <EOL> pywikibot . output ( u'<STR_LIT>' ) <EOL> for k , v in dateDict . items ( ) : <EOL> try : <EOL> dateDict [ k ] = int ( v ) <EOL> except ValueError : <EOL> pass <EOL> dateDict [ '<STR_LIT>' ] = tzoneFixedOffset ( self . site . siteinfo ( ) [ '<STR_LIT>' ] , <EOL> self . site . siteinfo ( ) [ '<STR_LIT>' ] ) <EOL> timestamp = datetime . datetime ( ** dateDict ) <EOL> else : <EOL> timestamp = None <EOL> return timestamp <EOL> class DiscussionThread ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , title , now ) : <EOL> self . title = title <EOL> self . now = now <EOL> self . content = "<STR_LIT>" <EOL> self . ts = TimeStripper ( ) <EOL> self . timestamp = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . title , len ( self . content ) ) <EOL> def feedLine ( self , line ) : <EOL> if not self . content and not line : <EOL> return <EOL> self . content += line + '<STR_LIT:\n>' <EOL> timestamp = self . ts . timestripper ( line ) <EOL> if not self . timestamp : <EOL> self . timestamp = timestamp <EOL> if timestamp : <EOL> self . timestamp = max ( self . timestamp , timestamp ) <EOL> def size ( self ) : <EOL> return len ( self . title ) + len ( self . content ) + <NUM_LIT:12> <EOL> def toText ( self ) : <EOL> return "<STR_LIT>" + self . title + '<STR_LIT>' + self . content <EOL> def shouldBeArchived ( self , Archiver ) : <EOL> algo = Archiver . get ( '<STR_LIT>' ) <EOL> reT = re . search ( r'<STR_LIT>' , algo ) <EOL> if reT : <EOL> if not self . timestamp : <EOL> return '<STR_LIT>' <EOL> maxage = str2time ( reT . group ( <NUM_LIT:1> ) ) <EOL> if self . now - self . timestamp > maxage : <EOL> return i18n . twtranslate ( Site . language , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : reT . group ( <NUM_LIT:1> ) } ) <EOL> return '<STR_LIT>' <EOL> class DiscussionPage ( pywikibot . Page ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , title , archiver , vars = None ) : <EOL> pywikibot . Page . __init__ ( self , Site , title ) <EOL> self . threads = [ ] <EOL> self . full = False <EOL> self . archiver = archiver <EOL> self . vars = vars <EOL> self . now = datetime . datetime . utcnow ( ) . replace ( tzinfo = tzoneUTC ( ) ) <EOL> try : <EOL> self . loadPage ( ) <EOL> except pywikibot . NoPage : <EOL> self . header = archiver . get ( '<STR_LIT>' , <EOL> message ( '<STR_LIT>' ) ) <EOL> if self . vars : <EOL> self . header = self . header % self . vars <EOL> def loadPage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . header = '<STR_LIT>' <EOL> self . threads = [ ] <EOL> self . archives = { } <EOL> self . archivedThreads = <NUM_LIT:0> <EOL> lines = self . get ( ) . split ( '<STR_LIT:\n>' ) <EOL> found = False <EOL> curThread = None <EOL> for line in lines : <EOL> threadHeader = re . search ( '<STR_LIT>' , line ) <EOL> if threadHeader : <EOL> found = True <EOL> if curThread : <EOL> self . threads . append ( curThread ) <EOL> curThread = DiscussionThread ( threadHeader . group ( <NUM_LIT:1> ) , self . now ) <EOL> else : <EOL> if found : <EOL> curThread . feedLine ( line ) <EOL> else : <EOL> self . header += line + '<STR_LIT:\n>' <EOL> if curThread : <EOL> self . threads . append ( curThread ) <EOL> pywikibot . output ( u'<STR_LIT>' % ( len ( self . threads ) , self ) ) <EOL> def feedThread ( self , thread , maxArchiveSize = ( <NUM_LIT> * <NUM_LIT> , '<STR_LIT:B>' ) ) : <EOL> self . threads . append ( thread ) <EOL> self . archivedThreads += <NUM_LIT:1> <EOL> if maxArchiveSize [ <NUM_LIT:1> ] == '<STR_LIT:B>' : <EOL> if self . size ( ) >= maxArchiveSize [ <NUM_LIT:0> ] : <EOL> self . full = True <EOL> elif maxArchiveSize [ <NUM_LIT:1> ] == '<STR_LIT:T>' : <EOL> if len ( self . threads ) >= maxArchiveSize [ <NUM_LIT:0> ] : <EOL> self . full = True <EOL> return self . full <EOL> def size ( self ) : <EOL> return len ( self . header ) + sum ( [ t . size ( ) for t in self . threads ] ) <EOL> def update ( self , summary , sortThreads = False ) : <EOL> if sortThreads : <EOL> pywikibot . output ( u'<STR_LIT>' ) <EOL> self . threads . sort ( key = lambda t : t . timestamp ) <EOL> newtext = re . sub ( '<STR_LIT>' , '<STR_LIT>' , self . header ) <EOL> for t in self . threads : <EOL> newtext += t . toText ( ) <EOL> if self . full : <EOL> summary += '<STR_LIT:U+0020>' + message ( '<STR_LIT>' ) <EOL> self . put ( newtext , comment = summary ) <EOL> class PageArchiver ( object ) : <EOL> """<STR_LIT>""" <EOL> algo = '<STR_LIT:none>' <EOL> def __init__ ( self , Page , tpl , salt , force = False ) : <EOL> self . attributes = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , False ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , False ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , False ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:1>' , False ] , <EOL> '<STR_LIT:key>' : [ '<STR_LIT>' , False ] , <EOL> } <EOL> self . tpl = tpl <EOL> self . salt = salt <EOL> self . force = force <EOL> self . Page = DiscussionPage ( Page . title ( ) , self ) <EOL> self . loadConfig ( ) <EOL> self . commentParams = { <EOL> '<STR_LIT>' : self . Page . title ( ) , <EOL> } <EOL> self . archives = { } <EOL> self . archivedThreads = <NUM_LIT:0> <EOL> self . monthNum2origNames , self . origNames2monthNum = Months . monthsDicts <EOL> def get ( self , attr , default = '<STR_LIT>' ) : <EOL> return self . attributes . get ( attr , [ default ] ) [ <NUM_LIT:0> ] <EOL> def set ( self , attr , value , out = True ) : <EOL> if attr == '<STR_LIT>' : <EOL> value = value . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) <EOL> self . attributes [ attr ] = [ value , out ] <EOL> def saveables ( self ) : <EOL> return [ a for a in self . attributes if self . attributes [ a ] [ <NUM_LIT:1> ] <EOL> and a != '<STR_LIT>' ] <EOL> def attr2text ( self ) : <EOL> return '<STR_LIT>' % ( self . tpl , <EOL> '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( a , self . get ( a ) ) <EOL> for a in self . saveables ( ) ] ) ) <EOL> def key_ok ( self ) : <EOL> s = new_hash ( ) <EOL> s . update ( self . salt + '<STR_LIT:\n>' ) <EOL> s . update ( self . Page . title ( ) . encode ( '<STR_LIT:utf8>' ) + '<STR_LIT:\n>' ) <EOL> return self . get ( '<STR_LIT:key>' ) == s . hexdigest ( ) <EOL> def loadConfig ( self ) : <EOL> pywikibot . output ( u'<STR_LIT>' % ( self . tpl , self . Page ) ) <EOL> found = False <EOL> for tpl in self . Page . templatesWithParams ( thistxt = self . Page . header ) : <EOL> if tpl [ <NUM_LIT:0> ] == self . tpl : <EOL> for param in tpl [ <NUM_LIT:1> ] : <EOL> item , value = param . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> self . set ( item . strip ( ) , value . strip ( ) ) <EOL> found = True <EOL> break <EOL> if not found : <EOL> raise MissingConfigError ( u'<STR_LIT>' ) <EOL> if not self . get ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise MissingConfigError ( u'<STR_LIT>' ) <EOL> def feedArchive ( self , archive , thread , maxArchiveSize , vars = None ) : <EOL> """<STR_LIT>""" <EOL> if not archive : <EOL> return <EOL> if not self . force and not self . Page . title ( ) + '<STR_LIT:/>' == archive [ : len ( self . Page . title ( ) ) + <NUM_LIT:1> ] and not self . key_ok ( ) : <EOL> raise ArchiveSecurityError <EOL> if archive not in self . archives : <EOL> self . archives [ archive ] = DiscussionPage ( archive , self , vars ) <EOL> return self . archives [ archive ] . feedThread ( thread , maxArchiveSize ) <EOL> def analyzePage ( self ) : <EOL> maxArchSize = str2size ( self . get ( '<STR_LIT>' ) ) <EOL> archCounter = int ( self . get ( '<STR_LIT>' , '<STR_LIT:1>' ) ) <EOL> oldthreads = self . Page . threads <EOL> self . Page . threads = [ ] <EOL> whys = [ ] <EOL> pywikibot . output ( u'<STR_LIT>' % len ( oldthreads ) ) <EOL> for t in oldthreads : <EOL> if len ( oldthreads ) - self . archivedThreads <= int ( self . get ( '<STR_LIT>' , <NUM_LIT:5> ) ) : <EOL> self . Page . threads . append ( t ) <EOL> continue <EOL> why = t . shouldBeArchived ( self ) <EOL> if why : <EOL> archive = self . get ( '<STR_LIT>' ) <EOL> vars = { <EOL> '<STR_LIT>' : archCounter , <EOL> '<STR_LIT>' : t . timestamp . year , <EOL> '<STR_LIT>' : t . timestamp . month , <EOL> '<STR_LIT>' : self . monthNum2origNames [ t . timestamp . month ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . monthNum2origNames [ t . timestamp . month ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : int ( time . strftime ( '<STR_LIT>' , t . timestamp . timetuple ( ) ) ) , <EOL> } <EOL> archive = pywikibot . Page ( Site , archive % vars ) . title ( ) <EOL> if self . feedArchive ( archive , t , maxArchSize , vars ) : <EOL> archCounter += <NUM_LIT:1> <EOL> self . set ( '<STR_LIT>' , str ( archCounter ) ) <EOL> whys . append ( why ) <EOL> self . archivedThreads += <NUM_LIT:1> <EOL> else : <EOL> self . Page . threads . append ( t ) <EOL> return set ( whys ) <EOL> def run ( self ) : <EOL> if not self . Page . botMayEdit ( Site . username ) : <EOL> return <EOL> whys = self . analyzePage ( ) <EOL> if self . archivedThreads < int ( self . get ( '<STR_LIT>' , <NUM_LIT:2> ) ) : <EOL> pywikibot . output ( u'<STR_LIT>' <EOL> % self . archivedThreads ) <EOL> return <EOL> if whys : <EOL> pywikibot . output ( u'<STR_LIT>' % self . archivedThreads ) <EOL> for a in sorted ( self . archives . keys ( ) ) : <EOL> self . commentParams [ '<STR_LIT:count>' ] = self . archives [ a ] . archivedThreads <EOL> comment = i18n . twntranslate ( language , <EOL> '<STR_LIT>' , <EOL> self . commentParams ) <EOL> self . archives [ a ] . update ( comment ) <EOL> rx = re . compile ( '<STR_LIT>' + self . tpl + '<STR_LIT>' , re . DOTALL ) <EOL> self . Page . header = rx . sub ( self . attr2text ( ) , self . Page . header ) <EOL> self . commentParams [ '<STR_LIT:count>' ] = self . archivedThreads <EOL> self . commentParams [ '<STR_LIT>' ] = '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' + a . title ( ) + '<STR_LIT>' for a in self . archives . values ( ) ] ) <EOL> if not self . commentParams [ '<STR_LIT>' ] : <EOL> self . commentParams [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . commentParams [ '<STR_LIT>' ] = '<STR_LIT:U+002CU+0020>' . join ( whys ) <EOL> comment = i18n . twntranslate ( language , <EOL> '<STR_LIT>' , <EOL> self . commentParams ) <EOL> self . Page . update ( comment ) <EOL> def main ( ) : <EOL> global Site , language <EOL> import sys <EOL> my_args = [ ] <EOL> for arg in pywikibot . handleArgs ( * sys . argv ) : <EOL> my_args . append ( arg ) <EOL> from optparse import OptionParser <EOL> parser = OptionParser ( usage = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:filename>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , type = '<STR_LIT:int>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> ( options , args ) = parser . parse_args ( args = my_args ) <EOL> if options . locale : <EOL> locale . setlocale ( locale . LC_TIME , options . locale . encode ( '<STR_LIT:utf8>' ) ) <EOL> if options . timezone : <EOL> os . environ [ '<STR_LIT>' ] = options . timezone <EOL> if hasattr ( time , '<STR_LIT>' ) : <EOL> time . tzset ( ) <EOL> if options . calc : <EOL> if not options . salt : <EOL> parser . error ( '<STR_LIT>' ) <EOL> s = new_hash ( ) <EOL> s . update ( options . salt + '<STR_LIT:\n>' ) <EOL> s . update ( options . calc + '<STR_LIT:\n>' ) <EOL> pywikibot . output ( u'<STR_LIT>' + s . hexdigest ( ) ) <EOL> return <EOL> if options . salt : <EOL> salt = options . salt <EOL> else : <EOL> salt = '<STR_LIT>' <EOL> if options . force : <EOL> force = True <EOL> else : <EOL> force = False <EOL> if options . lang : <EOL> pywikibot . default_code = options . lang <EOL> Site = pywikibot . getSite ( ) <EOL> language = Site . language ( ) <EOL> if options . simulate : <EOL> pywikibot . simulate = True <EOL> if not args or len ( args ) <= <NUM_LIT:1> : <EOL> pywikibot . output ( u'<STR_LIT>' ) <EOL> pywikibot . showHelp ( '<STR_LIT>' ) <EOL> return <EOL> Months . updateMonths ( site = Site ) <EOL> for a in args [ <NUM_LIT:1> : ] : <EOL> pagelist = [ ] <EOL> if not options . filename and not options . pagename : <EOL> if options . namespace is not None : <EOL> ns = [ str ( options . namespace ) ] <EOL> else : <EOL> ns = [ ] <EOL> for pg in generateTransclusions ( Site , a , ns ) : <EOL> pagelist . append ( pg ) <EOL> if options . filename : <EOL> for pg in file ( options . filename , '<STR_LIT:r>' ) . readlines ( ) : <EOL> pagelist . append ( pywikibot . Page ( Site , pg ) ) <EOL> if options . pagename : <EOL> pagelist . append ( pywikibot . Page ( Site , options . pagename , <EOL> defaultNamespace = <NUM_LIT:3> ) ) <EOL> pagelist = sorted ( pagelist ) <EOL> for pg in iter ( pagelist ) : <EOL> pywikibot . output ( u'<STR_LIT>' % pg ) <EOL> try : <EOL> Archiver = PageArchiver ( pg , a , salt , force ) <EOL> Archiver . run ( ) <EOL> time . sleep ( <NUM_LIT:10> ) <EOL> except : <EOL> pywikibot . output ( u'<STR_LIT>' % pg ) <EOL> traceback . print_exc ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> main ( ) <EOL> finally : <EOL> pywikibot . stopme ( ) </s>
