def load_league(filename, league: League): check_database_exists(filename) with Database(filename) as db: name_constraint = "{}='{}' {} {}".format(ColumnNames.Code.name, league.name, Keywords.COLLATE.name, Keywords.NOCASE.name) constraints = [ "{}='{}'".format(ColumnNames.Country.name, league.country), name_constraint ] season_rows = db.fetch_all_rows(Season.sql_table(), constraints) for season_row in season_rows: season = create_season_from_row(season_row) constraints = [ '{}={}'.format(ColumnNames.Season_ID.name, season_row[0]), '{}={}'.format(ColumnNames.Finished.name, Characters.TRUE.value) ] fixture_rows = db.fetch_all_rows(Fixture.sql_table(), constraints) for fixture_row in fixture_rows: fixture = create_fixture_from_row(fixture_row) if fixture: season.add_fixture(fixture) season.sort_fixtures()
def get_fixtures(db: Database, constraints: List[str]): fixture_rows = db.fetch_all_rows(Fixture.sql_table(), constraints) fixtures = [] for row in fixture_rows: fixture = create_fixture_from_row(row) fixtures.append(fixture) return fixtures
def fixtures_played(database: str, season: Season) -> bool: played = False with Database(database) as db: constraints = ["{}='{}'".format(ColumnNames.Season_ID.name, season.id)] fixture_rows = db.fetch_all_rows(Fixture.sql_table(), constraints) for row in fixture_rows: fixture = create_fixture_from_row(row) if fixture.home_team is not None and fixture.away_team is not None and not fixture.finished: lower_bound = datetime.today() + timedelta(days=-3) upper_bound = datetime.today() match_date = fixture.date.replace(tzinfo=None) if lower_bound <= match_date <= upper_bound: played = True return played
def get_fixtures(database: str, left_team: Team, right_team: Team): fixtures = [] with Database(database) as db: teams_constraint = "{}={} {} {}={}".format(ColumnNames.Home_ID.name, left_team.id, Keywords.AND.name, ColumnNames.Away_ID.name, right_team.id) finished_constraint = "{}={}".format(ColumnNames.Finished.name, Characters.TRUE.value) constraints = [teams_constraint, finished_constraint] fixtures_rows = db.fetch_all_rows(Fixture.sql_table(), constraints) for row in fixtures_rows: fixture = create_fixture_from_row(row) fixtures.append(fixture) return fixtures
def get_fixtures(database: str, team: Team, this_season: Season, venue: Venue): fixtures = [] with Database(database) as db: if venue == Venue.home: team_constraint = "{}={}".format(ColumnNames.Home_ID.name, team.id) elif venue == Venue.away: team_constraint = "{}={}".format(ColumnNames.Away_ID.name, team.id) else: team_constraint = "({}={} {} {}={})".format(ColumnNames.Home_ID.name, team.id, Keywords.OR.name, ColumnNames.Away_ID.name, team.id) finished_constraint = "{}={}".format(ColumnNames.Finished.name, Characters.TRUE.value) season_constraint = "{}={}".format(ColumnNames.Season_ID.name, this_season.id) constraints = [team_constraint, finished_constraint, season_constraint] fixtures_rows = db.fetch_all_rows(Fixture.sql_table(), constraints) for row in fixtures_rows: fixture = create_fixture_from_row(row) fixtures.append(fixture) return fixtures