def free_hit_used_in_gameweek(gameweek): """Use FPL API to determine whether a chip was played in the given gameweek""" fpl_team_data = fetcher.get_fpl_team_data(gameweek) if (fpl_team_data and "active_chip" in fpl_team_data.keys() and fpl_team_data["active_chip"] == "freehit"): return 1 else: return 0
def get_overall_points(gameweek=None): """ Get our total points """ data = fetcher.get_fpl_team_data() if not gameweek: return data["entry"]["summary_overall_points"] elif isinstance(gameweek, int) and gameweek <= len(data["history"]): return data["history"][gameweek - 1]["points"] else: print("Unknown gameweek") return 0
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)
def free_hit_used_in_gameweek(gameweek): """Use FPL API to determine whether a chip was played in the given gameweek""" if fetcher.get_fpl_team_data(gameweek)["active_chip"] == "freehit": return 1 else: return 0