graphPaname/app/data_request.py

24 lines
484 B
Python

from requests import get
from constants import URL
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
Raises an exception if there's an HTTP error
"""
url = format_url(dataset)
response = get(url)
response.raise_for_status()
data = response.json()
return data