def handleScheduleEntry(entry, title, name): global scheduleId global lastSchedule lastSchedule = DBEntry() time = getStr(entry, 'date') if time == None: time = '' lastSchedule.time = getTimestampFromDate(time) lastSchedule.name = name lastSchedule.division = getDivisionFromTitle(title) lastSchedule.region = getRegionFromTitle(title) lastSchedule.round = getRoundFromTitle(title) lastSchedule.id = scheduleId; try: mergedSchedule = False for candidateSchedule in scheduleMap[lastSchedule.region][lastSchedule.division][lastSchedule.round]: if ((candidateSchedule.time < lastSchedule.time + 2 * 60 * 60 * 1000) and (candidateSchedule.time > lastSchedule.time - 6 * 60 * 60 * 1000) and candidateSchedule.name == lastSchedule.name): lastSchedule = candidateSchedule mergedSchedule = True if not mergedSchedule: scheduleId += 1 scheduleMap[lastSchedule.region][lastSchedule.division][lastSchedule.round].append(lastSchedule) schedule.append(lastSchedule) except KeyError: print "KeyError for " + lastSchedule.region + " - " + lastSchedule.division + " - " + lastSchedule.round
def handleGame(match): matchid = len(matches) + 1 i = 1 p1wins = 0 p2wins = 0 while match.has("map" + str(i) + "win", False): newGame = DBEntry() newGame.mapname = getStr(match, "map" + str(i)) mapwinner = getInt(match, "map" + str(i) + "win") newGame.mapwinner = mapwinner if mapwinner == 1: p1wins = p1wins + 1 elif mapwinner == 2: p2wins = p2wins + 1 newGame.matchid = matchid newGame.vodlink = getStr(match, "vodgame" + str(i)) i = i + 1 games.append(newGame) return p1wins, p2wins
def handleStandings(wikicode): ranks = wikicode.filter(True, r'\|\d+', forcetype=Text) linkifiedNames = wikicode.filter_wikilinks() flagRace = wikicode.filter(True, r'flagRace', forcetype=Template) points = wikicode.filter(True, r"'''", forcetype=Tag) for i in range(0, len(flagRace)): standing = DBEntry() standing.rank = int((ranks[i][1 + ranks[i].rfind('\n'):].replace('|','')).strip()) standing.name = unicode(linkifiedNames[i + 2].title) standing.flag = unicode(flagRace[i].params[0].value) standing.race = unicode(flagRace[i].params[1].value) standing.points = int(unicode(points[i].contents)) standings.append(standing) i += 1
def handleMatch(match, matchTitle): newMatch = DBEntry() newMatch.matchtype = "group" newMatch.scheduleid = lastSchedule.id newMatch.player1name = getStr(match, "player1") newMatch.player2name = getStr(match, "player2") newMatch.player1race = getStr(match, "player1race") newMatch.player2race = getStr(match, "player2race") newMatch.player1flag = "-" newMatch.player2flag = "-" p1wins, p2wins = handleGame(match) newMatch.player1wins = p1wins newMatch.player2wins = p2wins newMatch.winner = getInt(match, "winner") matches.append(newMatch)
def handleBracketEntry(entry, prefix1, prefix2, prefixg, title): if entry.has(prefixg + 'details'): bracketMatchSummary = entry.get(prefixg + 'details').value.filter_templates(matches=r'BracketMatchSummary')[0] handleScheduleEntry(bracketMatchSummary, title, unicode(entry.get(prefix1[:2]).value).strip() if entry.has(prefix1[:2]) else unicode(entry.name).strip()) handleGame(bracketMatchSummary) newMatch = DBEntry() newMatch.matchtype = 'bracket' newMatch.scheduleid = lastSchedule.id newMatch.player1name = getStr(entry, prefix1) newMatch.player2name = getStr(entry, prefix2) newMatch.player1race = getStr(entry, prefix1 + 'race') newMatch.player2race = getStr(entry, prefix2 + 'race') newMatch.player1flag = getStr(entry, prefix1 + 'flag') newMatch.player2flag = getStr(entry, prefix2 + 'flag') newMatch.player1wins = getStr(entry, prefix1 + 'score') newMatch.player2wins = getStr(entry, prefix2 + 'score') if entry.has(prefix1 + 'win') and getInt(entry, prefix1 + 'win') > 0: newMatch.winner = 1 elif entry.has(prefix2 + 'win') and getInt(entry, prefix2 + 'win') > 0: newMatch.winner = 2 else: newMatch.winner = None matches.append(newMatch)
def handleGroupEntry(entry): newParticipant = DBEntry() for param in entry.params: for template in param.value.filter_templates(): if unicode(template.name) == 'player': newParticipant.name = getStr(template, '1') newParticipant.flag = getStr(template, 'flag') newParticipant.race = getStr(template, 'race') newParticipant.place = getInt(entry, 'place') newParticipant.matcheswon = getInt(entry, 'win_m') newParticipant.matcheslost = getInt(entry, 'lose_m') newParticipant.mapswon = getInt(entry, 'win_g') newParticipant.mapslost = getInt(entry, 'lose_g') newParticipant.result = getStr(entry, 'bg') newParticipant.scheduleid = lastSchedule.id participants.append(newParticipant)
def handleHeadsUpMatch(match): newMatch = DBEntry() newMatch.matchtype = 'bracket' newMatch.scheduleid = lastSchedule.id newMatch.player1name = getStr(match, 'player1') newMatch.player2name = getStr(match, 'player2') newMatch.player1race = getStr(match, 'player1race') newMatch.player2race = getStr(match, 'player2race') newMatch.player1flag = getStr(match, 'player1flag') newMatch.player2flag = getStr(match, 'player2flag') newMatch.player1wins, newMatch.player2wins = handleGame(match) if match.has('winner') and getInt(match, 'winner') > 0: newMatch.winner = getInt(match, 'winner') else: newMatch.winner = None matches.append(newMatch)