def get(self): w = self.response.out team_a = self.request.get('team_a') team_b = self.request.get('team_b') if team_a == "": w.write('illegal request, need name for team a') return if team_b == "": w.write('illegal request, need name for team b') return matches = Matchup.all().filter('team_a_name = ', team_a).filter('team_b_name = ', team_b).fetch(1) if len(matches) == 0: w.write('no matches found') return match = matches[0] w.write("<h1>%s vs %s</h1>" % (match.team_a_name, match.team_b_name)) w.write("<div>Match date: %s </div>" % match.date_match_formatted) bets = Bet.all().filter('match = ', match).fetch(1000) w.write("<table>") w.write("<tr><td>%s</td><td>Draw</td><td>%s</td><td>Recorded on</td><td>Current score</td></tr>" % (match.team_a_name, match.team_b_name)) for b in bets: w.write("<tr>") w.write("<td>%s</td>" % b.team_a_odds) w.write("<td>%s</td>" % b.draw_odds) w.write("<td>%s</td>" % b.team_b_odds) w.write("<td>%s</td>" % b.date_recorded) w.write("<td>%s</td>" % b.current_score) w.write("</tr>") w.write("</table>") w.write('found %s bets' % len(bets))
def parse_row(self, a, row): safea = a.string.encode('ascii', 'replace') score = re.search("[0-9]\-[0-9]", safea) source = self.url if score is not None: current_score = score.group() teams = safea.partition(' %s ' % current_score) else: teams = safea.partition(' vs ') team_a = teams[0] team_b = teams[2] match_date = row.td.a if match_date is None: match_date = row.td.div match_date = match_date['title'] # empty rows: team_a_raw_odds = row.find('td', {'class' : 'odds'}) if team_a_raw_odds == None: raise UnparsableException("Odds not found found for first team") return 0 team_b_raw_odds = row.find('td', {'class' : 'odds noBorder '}) if team_b_raw_odds == None: return 0 draw_raw_odds = row.find('td', {'class' : 'odds noBorder'}) if draw_raw_odds == None: return 0 team_a_odds = self.calc_odds(team_a_raw_odds.a.string.strip().encode('ascii', 'replace')) team_b_odds = self.calc_odds(team_b_raw_odds.a.string.strip().encode('ascii', 'replace')) draw_odds = self.calc_odds(draw_raw_odds.a.string.strip().encode('ascii', 'replace')) matchup = Matchup.all().filter('team_a_name = ', team_a).filter('team_b_name', team_b) result = matchup.fetch(1); date_match_formatted = parse_date(match_date.split()) if len(result) == 0: matchup = Matchup(team_a_name = team_a, team_b_name = team_b, source = source, date_match = match_date, date_match_formatted = date_match_formatted ) matchup.put() else: matchup = result[0] bet = Bet(team_a_odds = team_a_odds, team_b_odds = team_b_odds, draw_odds = draw_odds, match = matchup ) bet.put()
def get(self): w = self.response.out offset = self.request.get('offset') limit = self.request.get('limit') if limit is "": limit = 100 if offset is "": offset = 0 limit = int(limit) offset = int(offset) matches = Matchup.all()[offset:limit+offset] for m in matches: bets = Bet.all().filter("match = ", m) for b in bets: template = "%s;%s;%s;%s;%s;%s;%s" % (m.team_a_name, m.team_b_name, b.team_a_odds, b.team_b_odds,b.draw_odds,m.date_match_formatted, b.date_recorded) w.write(template) w.write("<br/>")
def get(self): w = self.response.out w.write("<a href='?till=24'>matches for the next 24h</a> ") w.write("<a href='?till=3'>matches for the next 3h</a> ") w.write("<a href='?till=3'>matches for the next hour</a> ") w.write("<a href='?till=all'>all matches</a>") w.write("<h1>matches:</h1>") matches = Matchup.all().order("date_match_formatted") span = self.request.get("till") if not span == "all": matches.filter("date_match_formatted > ", datetime.now() - timedelta(hours=2)) if not span == "" and not span == "all": span = int(span) matches.filter("date_match_formatted < ", datetime.now() + timedelta(hours=span)) for m in matches: match_name = "%s vs %s" % (m.team_a_name, m.team_b_name) fluctuations = self.calc_fluctuation(m) if fluctuations == 2: style = "color: orange" elif fluctuations > 2: style = "color: red" else: style = "" link = "<a style='%s' href='/match?team_a=%s&team_b=%s'>%s</a> at %s" % ( style, m.team_a_name, m.team_b_name, match_name, m.date_match_formatted, ) w.write(link) two_hours = timedelta(hours=2) diff = datetime.now() - m.date_match_formatted if diff < two_hours and diff > timedelta(): w.write(" <a style='color: red' href='%s'>live</a>" % m.source) w.write("<br/>")