26 lines
514 B
Python
26 lines
514 B
Python
from json import dump
|
|
|
|
from requests import get
|
|
|
|
from constants import FILES, 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
|