<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import wikipedia <EOL> import re , sys , pickle <EOL> import os . path <EOL> import time <EOL> cache = { } <EOL> def get ( site = None ) : <EOL> if site is None : <EOL> site = wikipedia . getSite ( ) <EOL> if site in cache : <EOL> watchlist = cache [ site ] <EOL> else : <EOL> fn = wikipedia . config . datafilepath ( '<STR_LIT>' , <EOL> '<STR_LIT>' % ( site . family . name , site . lang ) ) <EOL> try : <EOL> file_age = time . time ( ) - os . path . getmtime ( fn ) <EOL> if file_age > <NUM_LIT:30> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> : <EOL> wikipedia . output ( u'<STR_LIT>' ) <EOL> refresh ( site ) <EOL> except OSError : <EOL> refresh ( site ) <EOL> f = open ( fn , '<STR_LIT:r>' ) <EOL> watchlist = pickle . load ( f ) <EOL> f . close ( ) <EOL> cache [ site ] = watchlist <EOL> return watchlist <EOL> def isWatched ( pageName , site = None ) : <EOL> watchlist = get ( site ) <EOL> return pageName in watchlist <EOL> def refresh ( site , sysop = False ) : <EOL> if not site . has_api ( ) or site . versionnumber ( ) < <NUM_LIT:10> : <EOL> _refreshOld ( site ) <EOL> if not site . loggedInAs ( sysop = sysop ) : <EOL> site . forceLogin ( sysop = sysop ) <EOL> params = { <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT:list>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : wikipedia . config . special_page_limit , <EOL> '<STR_LIT>' : '<STR_LIT:title>' , <EOL> } <EOL> wikipedia . output ( u'<STR_LIT>' % repr ( site ) ) <EOL> watchlist = [ ] <EOL> while True : <EOL> data = wikipedia . query . GetData ( params , site , sysop = sysop ) <EOL> if '<STR_LIT:error>' in data : <EOL> raise RuntimeError ( '<STR_LIT>' % data ) <EOL> watchlist . extend ( [ w [ '<STR_LIT:title>' ] for w in data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] ) <EOL> if '<STR_LIT>' in data : <EOL> params [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> break <EOL> if sysop : <EOL> f = open ( wikipedia . config . datafilepath ( '<STR_LIT>' , <EOL> '<STR_LIT>' % ( site . family . name , site . lang ) ) , '<STR_LIT:w>' ) <EOL> else : <EOL> f = open ( wikipedia . config . datafilepath ( '<STR_LIT>' , <EOL> '<STR_LIT>' % ( site . family . name , site . lang ) ) , '<STR_LIT:w>' ) <EOL> pickle . dump ( watchlist , f ) <EOL> f . close ( ) <EOL> def _refreshOld ( site , sysop = False ) : <EOL> path = site . watchlist_address ( ) <EOL> wikipedia . output ( u'<STR_LIT>' % repr ( site ) ) <EOL> watchlistHTML = site . getUrl ( path , sysop = sysop ) <EOL> wikipedia . output ( u'<STR_LIT>' ) <EOL> watchlist = [ ] <EOL> for itemR in [ re . compile ( r'<STR_LIT>' ) , re . compile ( r'<STR_LIT>' ) ] : <EOL> for m in itemR . finditer ( watchlistHTML ) : <EOL> pageName = m . group ( <NUM_LIT:1> ) <EOL> watchlist . append ( pageName ) <EOL> if sysop : <EOL> f = open ( wikipedia . config . datafilepath ( '<STR_LIT>' , <EOL> '<STR_LIT>' % ( site . family . name , site . lang ) ) , '<STR_LIT:w>' ) <EOL> else : <EOL> f = open ( wikipedia . config . datafilepath ( '<STR_LIT>' , <EOL> '<STR_LIT>' % ( site . family . name , site . lang ) ) , '<STR_LIT:w>' ) <EOL> pickle . dump ( watchlist , f ) <EOL> f . close ( ) <EOL> def refresh_all ( new = False , sysop = False ) : <EOL> if new : <EOL> import config <EOL> wikipedia . output ( '<STR_LIT>' ) ; <EOL> for family in config . usernames : <EOL> for lang in config . usernames [ family ] : <EOL> refresh ( wikipedia . getSite ( code = lang , fam = family ) , sysop = sysop ) <EOL> for family in config . sysopnames : <EOL> for lang in config . sysopnames [ family ] : <EOL> refresh ( wikipedia . getSite ( code = lang , fam = family ) , sysop = sysop ) <EOL> else : <EOL> import dircache , time <EOL> filenames = dircache . listdir ( wikipedia . config . datafilepath ( '<STR_LIT>' ) ) <EOL> watchlist_filenameR = re . compile ( '<STR_LIT>' ) <EOL> for filename in filenames : <EOL> match = watchlist_filenameR . match ( filename ) <EOL> if match : <EOL> arr = match . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:->' ) <EOL> family = arr [ <NUM_LIT:0> ] <EOL> lang = '<STR_LIT:->' . join ( arr [ <NUM_LIT:1> : ] ) <EOL> refresh ( wikipedia . getSite ( code = lang , fam = family ) ) <EOL> def main ( ) : <EOL> all = False <EOL> new = False <EOL> sysop = False <EOL> for arg in wikipedia . handleArgs ( ) : <EOL> if arg == '<STR_LIT>' or arg == '<STR_LIT>' : <EOL> all = True <EOL> elif arg == '<STR_LIT>' : <EOL> new = True <EOL> elif arg == '<STR_LIT>' : <EOL> sysop = True <EOL> if all : <EOL> refresh_all ( sysop = sysop ) <EOL> elif new : <EOL> refresh_all ( new , sysop = sysop ) <EOL> else : <EOL> refresh ( wikipedia . getSite ( ) , sysop = sysop ) <EOL> watchlist = get ( wikipedia . getSite ( ) ) <EOL> wikipedia . output ( u'<STR_LIT>' % len ( watchlist ) ) <EOL> for pageName in watchlist : <EOL> wikipedia . output ( pageName , toStdout = True ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> main ( ) <EOL> finally : <EOL> wikipedia . stopme ( ) </s>
