def team_process(self, f): pattern = r""" <td>(\d+)</td> # rank <td>([A-Za-z. (),_0-9]+)</td> # name .* # rest of the line <td>(\d+)/(\d+)</td> # attempt, problemcount """ reg = re.compile( pattern, re.VERBOSE ) rankpat = r""" [A-Za-z]+\ ([A-Za-z]+\ \d+) # weekday, month, day \ \d\d:\d\d:\d\d\ [A-Za-z]+\ (\d+) # year """ rankreg = re.compile( rankpat, re.VERBOSE ) #finding the date of the event match = rankreg.search( f ) cdate = "" if match: cdate = match.group(1) + " " + match.group(2) logging.error( cdate ) logging.error( "finding something" ) else: logging.error( "nothing found" ) bests = "" results = reg.finditer(f) rank = 0; for result in results: # picking up details rank += 1 name = result.group(2) attempts = int(result.group(3)) solved = int(result.group(4)) earned = 0 # ignore autogenerated names if self.invalidName( name ): continue # pick up the earned points if rank <= 10 and int(solved) != 0: earned = points[ rank-1 ] if rank <= 3: if rank == 2: bests += ", " elif rank == 3: bests += " and " bests += name c = db.Query( Team ) c.filter( 'name =' , name ) teams = c.fetch(1) # updating database if len( teams ) == 0: # it was never in ranklist team = Team() team.name = name team.solve = solved team.points = earned team.contest = 1 team.attempt = attempts team.image = "img/nsu2.gif" if team.attempt: team.accuracy = str( round(( team.solve * 100. ) / team.attempt, 2) ) else: team.accuracy = str( 0.0 ) team.put() else: for team in teams: # it's one object though team.solve += solved team.points += earned team.contest += 1 team.attempt += attempts if team.attempt: team.accuracy = str( round(( team.solve * 100. ) / team.attempt,2) ) team.put() return [ bests, cdate ]
def team_process(self, f): pattern = r""" <td>(\d+)</td> # rank <td>([A-Za-z. (),_]+)</td> # name .* # rest of the line <td>(\d+)/(\d+)</td> # attempt, problemcount """ reg = re.compile( pattern, re.VERBOSE ) rankpat = r""" [A-Za-z]+\ ([A-Za-z]+\ \d+) # weekday, month, day \ \d\d:\d\d:\d\d\ [A-Za-z]+\ (\d+) # year """ rankreg = re.compile( rankpat, re.VERBOSE ) #finding the date of the event match = rankreg.search( f ) cdate = "" if match: cdate = match.group(1) + " " + match.group(2) logging.error( cdate ) logging.error( "finding something" ) else: logging.error( "nothing found" ) bests = "" results = reg.finditer(f) rank = 0; for result in results: # picking up details rank += 1 name = result.group(2) attempts = int(result.group(3)) solved = int(result.group(4)) earned = 0 # pick up the earned points if rank <= 10 and int(solved) != 0: earned = points[ rank-1 ] if rank <= 3: if rank == 2: bests += ", " elif rank == 3: bests += " and " bests += name c = db.Query( Team ) c.filter( 'name =' , name ) teams = c.fetch(1) # updating database if len( teams ) == 0: # it was never in ranklist team = Team() team.name = name team.solve = solved team.points = earned team.contest = 1 team.attempt = attempts team.image = "img/nsu2.gif" team.accuracy = str( round(( team.solve * 100. ) / team.attempt, 2) ) team.put() else: for team in teams: # it's one object though team.solve += solved team.points += earned team.contest += 1 team.attempt += attempts team.accuracy = str( round(( team.solve * 100. ) / team.attempt,2) ) team.put() return [ bests, cdate ]