def teamBrief(team): m = Matches() d = Divisions() matches = m.get_matches(lambda m: m.doesFeature(team)) last_result = m.lastResult(team) if last_result: last_result_index = matches.index(last_result) matches = [match for n, match in enumerate(matches) if abs(last_result_index - n) <= 2] else: matches = matches[:5] divisions = d.get_divisions(lambda d: d.doesFeatureTeam(team)) if len(divisions) == 1: division = divisions[0] row_of_interest = None for n, row in enumerate(division.rows): if row.team == team: row_of_interest = n if row_of_interest is not None: division.rows = [row for n, row in enumerate(division.rows) if abs(row_of_interest - n) <= 2] return render_template("teamDump.html", team=team, matches=matches, divisions=divisions)
def teams(): matches = Matches() teams = matches.teamNames("Wakefield", **request.args.to_dict()) # TODO Remove this hack teams = filter(lambda t: "Wanderers" not in t, teams) return render_template("teams.html", teams=teams, strings=ApplicationStrings())
def fixtures_by_team(): matches = Matches() teams = matches.teamNames("Wakefield", **request.args.to_dict()) matches_by_team = OrderedDict() for team in teams: team_matches = matches.get_matches(lambda m: m.doesFeature(team)) team_matches.sort() matches_by_team[team] = team_matches return render_template("fixtures_by_team.html", matches_by_team = matches_by_team)
def test_get_matches_team_feature_condition(self): _ = None m = Matches(auto_init_data=False) m1 = Match(_, _, _, "Team B", _, _, _, _, _) m2 = Match(_, _, _, "Team A", _, _, _, _, _) m3 = Match(_, _, _, "Team B", _, _, _, _, _) m.listOfMatches = [m1, m2, m3] expected = [m1, m3] actual = m.get_matches() self.assertEqual(expected, actual)
def test_get_matches(self): _ = None m = Matches(auto_init_data=False) m1 = Match(_, _, _, _, _, _, _, _, _) m2 = Match(_, _, _, _, _, _, _, _, _) m3 = Match(_, _, _, _, _, _, _, _, _) m.listOfMatches = [m1, m2, m3] expected = [m1, m2, m3] actual = m.get_matches() self.assertEqual(expected, actual)
def team(team): matches = Matches().get_matches(lambda m: m.doesFeature(team)) d_cond = lambda d: d.doesFeatureTeam(team) divisions = Divisions().get_divisions(d_cond) return render_template("teamDump.html", team=team, matches=matches, divisions=divisions)
def team_ics(team): matches = Matches().get_matches(lambda m: m.doesFeature(team)) c = Calendar() for m in matches: if not m._date: continue e = Event(uid=fixture_uid(m), location=m.venue) e.name = "%s vs %s" % (m.home, m.away) if not m._time: m._time = time(0,0,0) begin = datetime(m._date.year, m._date.month, m._date.day, m._time.hour, m._time.minute, m._time.second) begin = arrow.get(begin, 'Europe/London') e.begin = begin e.duration = timedelta(minutes=90) c.events.append(e) return Response(c, mimetype='text/calendar')
def get_tweets(the_datetime, interval_minutes): interval_in_seconds = interval_minutes * 60 for current_match in Matches().listOfMatches: if 'Wakefield' in current_match.home: if current_match._time is None: continue if current_match.isPostponed: continue full_date = datetime( current_match._date.year, current_match._date.month, current_match._date.day, current_match._time.hour, current_match._time.minute, current_match._time.second ) td = full_date - the_datetime if 0 < td.total_seconds() <= interval_in_seconds: pitch = get_pitch_from_note(current_match.note) opener = get_opener() template = "%s: %s vs %s%s, %s push back #GreenArmy" tweet = template % ( opener, current_match.home, current_match.away, pitch, current_match.time) yield tweet
def fixtures_by_date(): matches = Matches() teams = matches.teamNames("Wakefield", **request.args.to_dict()) matches = matches.get_matches(lambda m: m.home in teams or m.away in teams) matches.sort() # First date in the future dates = { m._date for m in matches } dates_in_the_future = { d for d in dates if d > datetime.now() } if dates_in_the_future: scroll_to_date = min(dates_in_the_future) else: scroll_to_date = min(dates) return render_template("fixtures_by_date.html", matches = matches, scroll_to_date = scroll_to_date)
def home(): matches = Matches() teams = matches.teamNames("Wakefield") kwargs = request.args.to_dict() nextMatches = matches.getNextMatches(teams, **kwargs) lastResults = matches.getLastResults(teams, **kwargs) todaysMatches = matches.getTodaysMatches(teams, **kwargs) dashboard_items = [ elements.LastResultDashboardItem(lastResults), elements.NextMatchDashboardItem(nextMatches), elements.TwitterFeedDashboardItem(), elements.TodaysMatchesDashboardItem(todaysMatches) ] # Only include dashboard items that have content to display. dashboard_items = [di for di in dashboard_items if di.has_content()] return render_template("dashboard.html", strings=ApplicationStrings(), dashboard_items=dashboard_items)
def recent_form(): matches = Matches() teams = matches.teamNames("Wakefield") recent_form = matches.recentForm(teams, **request.args.to_dict()) return render_template("recent_form.html", recent_form=recent_form)
def last_result(): matches = Matches() teams = matches.teamNames("Wakefield") lastResults = matches.getLastResults(teams, **request.args.to_dict()) return render_template("last_result.html", lastResults=lastResults)
def next_match(): matches = Matches() teams = matches.teamNames("Wakefield") nextMatches = matches.getNextMatches(teams, **request.args.to_dict()) return render_template("next_match.html", nextMatches=nextMatches)