INNER CODE UNIT · Python
req_prem_fixtures_id
mhaythornthwaite/Football_Prediction_Project · 01_api_data_request.py:74
def req_prem_fixtures_id(season_code, year=YEAR_str):
#request to the api for the data
premier_league_fixtures_raw = get_api_data(base_url, f'/fixtures/league/{season_code}/')
#cleaning the data in preparation for loading into a dataframe
premier_league_fixtures_sliced = slice_api(premier_league_fixtures_raw, 33, 2)
#saving the clean data as a json file
save_api_output(f'{year}_premier_league_fixtures', premier_league_fixtures_sliced, json_data_path = 'prem_clean_fixtures_and_dataframes/')
#loading the json file as a DataFrame
premier_league_fixtures_df = read_json_as_pd_df(f'{year}_premier_league_fixtures.json', json_data_path='prem_clean_fixtures_and_dataframes/')
return premier_league_fixtures_df
#requesting data on the premier leagues, we will use this response to get the league_id of the season we were interested in
if request_league_ids:
leagues = premier_league_fixtures_raw = get_api_data(base_url, 'leagues/country/England/2024')