|
11 | 11 |
|
12 | 12 | # Allow overriding the data repo base via env var for easy testing |
13 | 13 | # Must end with a trailing slash and point to a raw.githubusercontent.com base |
14 | | -REMOTE_DATA_REPO_URL = os.getenv( |
15 | | - "DEPT_DATA_URL", |
16 | | - "https://raw.githubusercontent.com/TigerAppsOrg/Princeton-Departmental-Data/old/", |
17 | | -) |
18 | | - |
19 | | -# connect/read timeouts so requests never hang workers indefinitely |
20 | | -_HTTP_TIMEOUT = (3.05, 7) |
| 14 | +import pathlib |
21 | 15 |
|
| 16 | +_LOCAL_DATA_DIR = pathlib.Path(__file__).resolve().parent.parent.parent / "requirements_data" |
22 | 17 |
|
23 | 18 | @lru_cache(maxsize=256) |
24 | | -def _fetch_remote_yaml(path: str): |
25 | | - """ |
26 | | - Fetch and parse YAML from the remote requirements repository with a timeout. |
27 | | -
|
28 | | - Results are cached in-process to avoid repeated network requests on hot paths. |
29 | | - """ |
30 | | - resp = requests.get(REMOTE_DATA_REPO_URL + path, timeout=_HTTP_TIMEOUT) |
31 | | - resp.raise_for_status() |
32 | | - return yaml.safe_load(resp.text) |
| 19 | +def _load_yaml(path: str): |
| 20 | + """Load and parse YAML from the local requirements data directory.""" |
| 21 | + filepath = _LOCAL_DATA_DIR / path |
| 22 | + return yaml.safe_load(filepath.read_text()) |
33 | 23 |
|
34 | 24 |
|
35 | 25 | MAJORS_LOCATION = "majors/" # relative path to folder containing the major requirements JSONs |
@@ -149,7 +139,7 @@ def check_requirements(req_file, courses, year): |
149 | 139 | :returns: A simplified json with info about how much of each requirement is satisfied |
150 | 140 | :rtype: (bool, dict, dict) |
151 | 141 | """ |
152 | | - req = _fetch_remote_yaml(req_file) |
| 142 | + req = _load_yaml(req_file) |
153 | 143 | courses = _init_courses(courses, req, year) |
154 | 144 | req = _init_req(req, year) |
155 | 145 | _mark_possible_reqs(req, courses) |
@@ -205,7 +195,7 @@ def get_courses_by_path(path): |
205 | 195 | req_filepath = os.path.join(DEGREES_LOCATION, filename) |
206 | 196 | else: |
207 | 197 | raise ValueError("Path malformatted.") |
208 | | - req = _fetch_remote_yaml(req_filepath) |
| 198 | + req = _load_yaml(req_filepath) |
209 | 199 | _init_year_switch(req, year) |
210 | 200 | subreq = _get_req_by_path(req, path, year) |
211 | 201 | if not subreq: |
|
0 commit comments