def fill_session_team(team_id, session_id, dbsession=DBSESSION): """ Use the FPL API to get list of players in an FPL squad with id=team_id, then fill the session team with these players. """ # first reset the team reset_session_team(session_id, dbsession) # now query the API players = fetcher.get_fpl_team_data(get_last_finished_gameweek(), team_id) player_ids = [p["element"] for p in players] for pid in player_ids: add_session_player(pid, session_id, dbsession) team_history = fetcher.get_fpl_team_history_data()["current"] index = (get_last_finished_gameweek() - 1 ) # as gameweek starts counting from 1 but list index starts at 0 budget = team_history[index]["value"] set_session_budget(budget, session_id) return player_ids
import json from airsenal.framework.season import CURRENT_SEASON from airsenal.framework.utils import fetcher sdata = fetcher.get_current_summary_data() with open(f"../data/FPL_{CURRENT_SEASON}.json", "w") as f: json.dump(sdata, f) fixtures = fetcher.get_fixture_data() with open(f"../data/fixture_data_{CURRENT_SEASON}.json", "w") as f: json.dump(fixtures, f) history = fetcher.get_fpl_team_history_data() with open(f"../data/airsenal_history_{CURRENT_SEASON}.json", "w") as f: json.dump(history, f) transfers = fetcher.get_fpl_transfer_data() with open(f"../data/airsenal_transfer_{CURRENT_SEASON}.json", "w") as f: json.dump(transfers, f) gws = [fetcher.get_fpl_team_data(gw) for gw in range(1, 39)] with open(f"../data/airsenal_gw_{CURRENT_SEASON}.json", "w") as f: json.dump(gws, f)