def prepare_competition_page(id): connector = Connector() json_matches = connector.send_get('competitions/{}/matches/'.format(id)) matches = json.loads(json_matches) json_teams = connector.send_get('competitions/{}/teams/'.format(id)) teams = json.loads(json_teams) proper_teams = [] [proper_teams.append(Team(team['id'], team['name'])) for team in teams] for match in matches: if match['status'] in ['scheduled', 'in_play']: continue team_indexes = [] for i, team in enumerate(proper_teams): if team.id == get_team_id_from_match(match, 0): team_indexes.append(i) for i, team in enumerate(proper_teams): if team.id == get_team_id_from_match(match, 1): team_indexes.append(i) for i, index in enumerate(team_indexes): proper_teams[index].played_matches += 1 proper_teams[team_indexes[i]].scored += match['teams'][i]['goals'] proper_teams[team_indexes[i]].conceded += match['teams'][ (i + 1) % 2]['goals'] if match['teams'][0]['goals'] > match['teams'][1]['goals']: proper_teams[team_indexes[0]].points += 3 proper_teams[team_indexes[0]].won += 1 proper_teams[team_indexes[1]].lost += 1 elif match['teams'][0]['goals'] == match['teams'][1]['goals']: for index in team_indexes: proper_teams[index].points += 1 proper_teams[index].drawn += 1 else: proper_teams[team_indexes[1]].points += 3 proper_teams[team_indexes[1]].won += 1 proper_teams[team_indexes[0]].lost += 1 proper_teams.sort(key=lambda x: x.points, reverse=True) return render_template('competition.html', competition_id=id, matches=matches, teams=proper_teams)
def competition_matches(id): connector = Connector() json_matches = connector.send_get('competitions/{}/matches/'.format(id)) json_teams = connector.send_get('competitions/{}/teams/'.format(id)) matches = json.loads(json_matches) teams = json.loads(json_teams) matches_to_display = [] for i in range(0, len(matches)): team1 = get_team_by_id(get_team_id(matches[i]['teams'][0]), teams) team2 = get_team_by_id(get_team_id(matches[i]['teams'][1]), teams) if matches[i]['teams'][0]['is_host']: home_team = TeamInMatch(matches[i]['teams'][0], team1) away_team = TeamInMatch(matches[i]['teams'][1], team2) else: home_team = TeamInMatch(matches[i]['teams'][0], team2) away_team = TeamInMatch(matches[i]['teams'][1], team1) matches_to_display.append(Match(matches[i], home_team, away_team)) return render_template('matches.html', competition_id=id, matches=matches_to_display)
def competition_match(competition_id, match_id): connector = Connector() json_match = connector.send_get('competitions/{}/matches/{}/'.format( competition_id, match_id)) json_teams = connector.send_get( 'competitions/{}/teams/'.format(competition_id)) match = json.loads(json_match) teams = json.loads(json_teams) team1 = get_team_by_id(get_team_id(match['teams'][0]), teams) team2 = get_team_by_id(get_team_id(match['teams'][1]), teams) if match['teams'][0]['is_host']: home_team = TeamInMatch(match['teams'][0], team1) away_team = TeamInMatch(match['teams'][1], team2) else: home_team = TeamInMatch(match['teams'][0], team2) away_team = TeamInMatch(match['teams'][1], team1) match_to_display = Match(match, home_team, away_team) return render_template('match.html', match=match_to_display, competition_id=competition_id)
def prepare_index_page(): todays_date = datetime.now().strftime('%d-%m-%Y') connector = Connector() json_matches = connector.send_get('matches/today/') json_teams = connector.send_get('teams/') matches = json.loads(json_matches) teams = json.loads(json_teams) matches_to_display = [] for i in range(0, len(matches)): team1 = get_team_by_id(get_team_id(matches[i]['teams'][0]), teams) team2 = get_team_by_id(get_team_id(matches[i]['teams'][1]), teams) if matches[i]['teams'][0]['is_host']: home_team = TeamInMatch(matches[i]['teams'][0], team1) away_team = TeamInMatch(matches[i]['teams'][1], team2) else: home_team = TeamInMatch(matches[i]['teams'][0], team2) away_team = TeamInMatch(matches[i]['teams'][1], team1) matches_to_display.append(Match(matches[i], home_team, away_team)) return render_template('index.html', date=todays_date, matches=matches_to_display)
def team(id): connector = Connector() json_team = connector.send_get('teams/{}/'.format(id)) team = json.loads(json_team) json_people = connector.send_get('people/') people = json.loads(json_people) proper_players = [] for player in team['players']: for person in people: if get_id_from_url(player['person']) == person['id']: proper_player = Player(id=person['id'], name=person['name'], position=player['position'], birth_date=person['birth_date'], shirt_number=player['shirt_number'], nationality=person['nationality']) proper_players.append(proper_player) decks_amount = math.ceil(len(proper_players) / 3) return render_template('team.html', team=team, players=proper_players, decks_amount=decks_amount)
def competitions(): connector = Connector() json_competitions = connector.send_get('competitions/') competitions = json.loads(json_competitions) return render_template('competitions.html', competitions=competitions)