Skip to content

Commit

Permalink
skip player transfer history for api error
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Sep 21, 2024
1 parent 48fd1a8 commit e7d441a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions data/raw/transfermarkt-api.dvc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
outs:
- md5: 85ec361a6a3a5b016b109905bb923cf8.dir
size: 575799152
- md5: cf71294799213d3d4ff38dbc49b67660.dir
size: 573260515
nfiles: 15
hash: md5
path: transfermarkt-api
11 changes: 9 additions & 2 deletions scripts/acquiring/transfermarkt-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ async def fetch_data(session, url, player_id):
}

async with session.get(url=url, headers=headers, ssl=False) as response:
json = await response.json()
return {"response": json, "player_id": player_id}
try:
json = await response.json()
return {"response": json, "player_id": player_id}
except aiohttp.ContentTypeError as e:
logging.error(f"Failed to fetch data for player {player_id}: {e}")
return {"response": None, "player_id": player_id}

# for each player id, get the market value data from the API
async def get_market_values(player_ids: List[int]) -> List[dict]:
Expand Down Expand Up @@ -154,6 +158,9 @@ def run_for_season(season: int) -> None:
market_values = asyncio.run(get_market_values(player_ids))
transfers = asyncio.run(get_transfers(player_ids))

# filter out player ids in responses that are not in the original list
transfers = [item for item in transfers if item["player_id"] in player_ids]

logging.info(f"Persisting market values and transfers for season {season}")

# persist market values and transfers to files
Expand Down

0 comments on commit e7d441a

Please sign in to comment.