#NEWLINE# def get_submissions( self , last_retrieved ) : #NEWLINE# #INDENT# if self . retrieve_failed : #NEWLINE# #INDENT# return ( - 1 ) #NEWLINE# #UNINDENT# if self . handle : #NEWLINE# #INDENT# handle = self . handle #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( - 1 ) #NEWLINE# #UNINDENT# user_url = ( 'http://www.codechef.com/recent/user?user_handle=' + handle ) #NEWLINE# tmp = get_request ( user_url , headers = { #NEWLINE# #INDENT# 'User-Agent' : user_agent , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( ( handle == ( - 1 ) ) or ( tmp == { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) : #NEWLINE# #INDENT# return tmp #NEWLINE# #UNINDENT# d = ast . literal_eval ( tmp . text ) #NEWLINE# max_page = d [ 'max_page' ] #NEWLINE# submissions = { #NEWLINE# #INDENT# handle : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# it = 1 #NEWLINE# tmp_const = time . strptime ( current . INITIAL_DATE , '%Y-%m-%d %H:%M:%S' ) #NEWLINE# if ( tmp_const == last_retrieved ) : #NEWLINE# #INDENT# threads = [ ] #NEWLINE# for i in xrange ( max_page ) : #NEWLINE# #INDENT# threads . append ( gevent . spawn ( self . parallelize_codechef , handle , i , last_retrieved ) ) #NEWLINE# #UNINDENT# gevent . joinall ( threads ) #NEWLINE# return self . submissions #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for page in xrange ( 0 , max_page ) : #NEWLINE# #INDENT# user_url = ( ( ( 'http://www.codechef.com/recent/user?user_handle=' + handle ) + '&page=' ) + str ( page ) ) #NEWLINE# tmp = get_request ( user_url , headers = { #NEWLINE# #INDENT# 'User-Agent' : user_agent , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( tmp == ( - 1 ) ) : #NEWLINE# #INDENT# return ( - 1 ) #NEWLINE# #UNINDENT# d = ast . literal_eval ( tmp . text ) [ 'content' ] #NEWLINE# submissions [ handle ] [ page ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# x = bs4 . BeautifulSoup ( d ) #NEWLINE# for i in x . find_all ( 'tr' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( i [ 'class' ] [ 0 ] == 'kol' ) : #NEWLINE# #INDENT# submissions [ handle ] [ page ] [ it ] = [ ] #NEWLINE# submission = submissions [ handle ] [ page ] [ it ] #NEWLINE# append = submission . append #NEWLINE# tos = i . contents [ 0 ] . contents [ 0 ] #NEWLINE# tos = str ( ast . literal_eval ( repr ( tos ) . replace ( '\\' , '' ) ) ) #NEWLINE# tos = self . parsetime ( tos ) #NEWLINE# curr = time . strptime ( str ( tos ) , '%Y-%m-%d %H:%M:%S' ) #NEWLINE# if ( curr <= last_retrieved ) : #NEWLINE# #INDENT# return submissions #NEWLINE# #UNINDENT# append ( str ( tos ) ) #NEWLINE# prob = i . contents [ 1 ] . contents [ 0 ] #NEWLINE# prob [ 'href' ] = ( 'http://www.codechef.com' + prob [ 'href' ] ) #NEWLINE# problem_link = eval ( repr ( prob [ 'href' ] ) . replace ( '\\' , '' ) ) #NEWLINE# append ( problem_link ) #NEWLINE# try : #NEWLINE# #INDENT# append ( prob . contents [ 0 ] ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# append ( '' ) #NEWLINE# #UNINDENT# stat = i . contents [ 2 ] . contents [ 0 ] #NEWLINE# stat = stat . find ( 'img' ) [ 'src' ] #NEWLINE# stat = repr ( stat ) . replace ( '\\' , '' ) #NEWLINE# stat = stat [ 7 : ( - 5 ) ] #NEWLINE# st = 'AC' #NEWLINE# if ( stat == 'tick-icon' ) : #NEWLINE# #INDENT# st = 'AC' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( stat == 'cross-icon' ) : #NEWLINE# #INDENT# st = 'WA' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( stat == 'alert-icon' ) : #NEWLINE# #INDENT# st = 'CE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( stat == 'runtime-error' ) : #NEWLINE# #INDENT# st = 'RE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( stat == 'clock_error' ) : #NEWLINE# #INDENT# st = 'TLE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# st = 'OTH' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# append ( st ) #NEWLINE# pts = i . contents [ 2 ] . contents [ 0 ] . contents #NEWLINE# try : #NEWLINE# #INDENT# if ( len ( pts ) >= 5 ) : #NEWLINE# #INDENT# points = ( ( pts [ 2 ] + ' ' ) + pts [ 4 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# points = pts [ 2 ] #NEWLINE# #UNINDENT# #UNINDENT# except IndexError : #NEWLINE# #INDENT# if ( st == 'AC' ) : #NEWLINE# #INDENT# points = '100' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# points = '0' #NEWLINE# #UNINDENT# #UNINDENT# append ( points ) #NEWLINE# append ( i . contents [ 3 ] . contents [ 0 ] . strip ( ) ) #NEWLINE# view_link = '' #NEWLINE# append ( view_link ) #NEWLINE# it += 1 #NEWLINE# #UNINDENT# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return submissions