graphPaname/app/data_request.py

24 lines
484 B
Python
Raw Normal View History

2020-05-21 18:45:51 +02:00
from requests import get
2020-06-12 19:21:50 +02:00
2020-06-14 00:14:09 +02:00
from constants import URL
2020-05-21 18:45:51 +02:00
2020-06-05 13:48:47 +02:00
def format_url(dataset) -> str:
"""
Constructs the API's URL for the requested dataset
"""
link = URL.format(dataset)
return link
def request_dataset(dataset):
"""
Fetches the requested dataset from opendata's API
2020-06-12 19:21:50 +02:00
Raises an exception if there's an HTTP error
2020-06-05 13:48:47 +02:00
"""
url = format_url(dataset)
response = get(url)
response.raise_for_status()
data = response.json()
return data