Skip to content

Commit

Permalink
fix keyerror if coinmarket cap does not return quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Oct 24, 2023
1 parent fecf4fb commit 1cce575
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /bin/bash
PROJECT := graphsense-lib
VENV := venv
RELEASE := 'v23.09'
RELEASESEM := 'v1.8.1'
RELEASESEM := 'v1.8.2'

all: format lint test build

Expand Down
12 changes: 8 additions & 4 deletions src/graphsenselib/rates/coinmarketcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ def parse_cmc_historical_response(
"""Parse historical exchange rates (JSON) from CoinMarketCap."""

json_data = json.loads(response.content)
json_data = [
[elem["time_close"][:10], elem["quote"]["USD"]["close"]]
for elem in json_data["data"]["quotes"]
]
if "data" in json_data and "quotes" in json_data["data"]:
json_data = [
[elem["time_close"][:10], elem["quote"]["USD"]["close"]]
for elem in json_data["data"]["quotes"]
]
else:
logger.error("Error: Coinmarketcap did not return any quotes.")
raise SystemExit(100)

return pd.DataFrame(json_data, columns=["date", "USD"])

Expand Down

0 comments on commit 1cce575

Please sign in to comment.