def fill_results_from_api(gw_start, gw_end, season, dbsession): fetcher = FPLDataFetcher() matches = fetcher.get_fixture_data() for m in matches: if not m["finished"]: continue gameweek = m["event"] if gameweek < gw_start or gameweek > gw_end: continue home_id = m["team_h"] away_id = m["team_a"] home_team = None away_team = None for k, v in alternative_team_names.items(): if str(home_id) in v: home_team = k elif str(away_id) in v: away_team = k if not home_team: raise ValueError("Unable to find team with id {}".format(home_id)) if not away_team: raise ValueError("Unable to find team with id {}".format(away_id)) home_score = m["team_h_score"] away_score = m["team_a_score"] f = _find_fixture(season, home_team, away_team, dbsession) res = Result() res.fixture = f res.home_score = int(home_score) res.away_score = int(away_score) dbsession.add(res) dbsession.commit()
def fill_results_from_csv(input_file, season, dbsession): for line in input_file.readlines()[1:]: ( date, home_team, away_team, home_score, away_score, gameweek, ) = line.strip().split(",") print(line.strip()) for k, v in alternative_team_names.items(): if home_team in v: home_team = k elif away_team in v: away_team = k ## query database to find corresponding fixture tag = get_latest_fixture_tag(season, dbsession) f = _find_fixture(season, home_team, away_team, dbsession) res = Result() res.fixture = f res.home_score = int(home_score) res.away_score = int(away_score) dbsession.add(res) dbsession.commit()