The library folder contains two files that provide common utilities shared across all python files.
api.py
This file is syntactic sugar around the API, abstracting the API requests from the files using them. This provides easy refactoring when the API changes, without having to rewrite every file. Functions always look like this:
BASE_URL = "http://localhost:50000"
def get_answers_for(scale: str) -> list[dict]:
res = requests.get("{0}/v1/answers/{1}".format(BASE_URL, scale))
if res.status_code != 200:
raise requests.RequestException(
f"Request was not fullfilled successfully. Server responded with {res.status_code}")
return res.json()
Every function requests the endpoint, catches if the answer is not the desired status code and returns the result as a dictionary. If you changed the container port during the creation of the container or if you're running it on another server, you can simply change BASE_URL
to the URL of the API, without having to change the functions themselves.
constants.py
The constants file contains fixed values that are used in at least two code files. Mostly you will find path creation here
RAW_DATA_PATH = os.path.normpath(os.path.join(os.getcwd(), "..", "raw_data"))
If you changed the structure of folders, you should change the path creation here too, files using these constants will automatically pick up the new path.