Commit 06fa18ec authored by Chris Jewell's avatar Chris Jewell
Browse files

Merge branch 'fix-download-retry' into 'master'

Fix download retry

See merge request !35
parents d8069a6a 754663e3
"""Loads COVID-19 case data""" """Loads COVID-19 case data"""
import time
from warnings import warn from warnings import warn
import requests import requests
import json import json
...@@ -45,10 +46,23 @@ class CasesData: ...@@ -45,10 +46,23 @@ class CasesData:
""" """
Placeholder, in case we wish to interface with an API. Placeholder, in case we wish to interface with an API.
""" """
response = requests.get(url) max_tries = 5
content = json.loads(response.content) secs = 5
df = pd.read_json(json.dumps(content["body"])) for i in range(max_tries):
return df try:
print("Attempting to download...", end="", flush=True)
response = requests.get(url)
content = json.loads(response.content)
df = pd.read_json(json.dumps(content["body"]))
print("Success", flush=True)
return df
except ConnectionResetError:
print("Failed", flush=True)
time.sleep(secs * 2 ** i)
raise ConnectionError(
f"Data download timed out after {max_tries} attempts"
)
def getCSV(file): def getCSV(file):
""" """
......
...@@ -38,10 +38,13 @@ black = "^20.8b1" ...@@ -38,10 +38,13 @@ black = "^20.8b1"
pytest = "^6.2.1" pytest = "^6.2.1"
jedi = "^0.17.2" jedi = "^0.17.2"
[tool.poetry-dynamic-versioning]
enable = true
[tool.black] [tool.black]
line-length = 80 line-length = 80
include = '\.pyi?$' include = '\.pyi?$'
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment