-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d665d9
commit fd20217
Showing
8 changed files
with
98 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Optional | ||
|
||
import pandas as pd | ||
import requests | ||
|
||
|
||
BASE_URL = "http://localhost:8000" | ||
|
||
|
||
def api( | ||
section: str, | ||
path: str, | ||
path_extra_1: Optional[str] = None, | ||
path_extra_2: Optional[ | ||
str | ||
] = None, # TODO: this is pretty silly, but it works for now | ||
as_json: bool = False, | ||
params: Optional[dict] = None, | ||
): | ||
""" | ||
Fetches data from the backend API. To find the corresponding | ||
path, look at the `backend/api/` directory. It should be setup | ||
so that the `section` is the name of the file, the `path` is the | ||
function inside the file. | ||
Args: | ||
section (str): The section of the API to fetch from. | ||
path (str): The path of the API to fetch from. | ||
path_extra (Optional[str]): An optional extra path to append to the path. | ||
as_json (bool): Whether to return the response as JSON. | ||
Returns: | ||
The response from the API. | ||
""" | ||
if path_extra_1: | ||
path = f"{path}/{path_extra_1}" | ||
if path_extra_2: | ||
path = f"{path}/{path_extra_2}" | ||
if params: | ||
response = requests.get(f"{BASE_URL}/api/{section}/{path}", params=params) | ||
else: | ||
response = requests.get(f"{BASE_URL}/api/{section}/{path}") | ||
|
||
if as_json: | ||
return response.json() | ||
|
||
try: | ||
return pd.DataFrame(response.json()) | ||
except ValueError: | ||
return response.json() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.