From dc75820ce2cc17bda54e71902c45bf1363cec8cf Mon Sep 17 00:00:00 2001 From: Shiva Menta Date: Thu, 29 Aug 2024 17:05:20 -0500 Subject: [PATCH] lint --- .../courses/management/commands/loadstatus.py | 1 + .../management/commands/pathopendata.py | 67 ++++++++++--------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/backend/courses/management/commands/loadstatus.py b/backend/courses/management/commands/loadstatus.py index b8872bc7..8880ddd4 100644 --- a/backend/courses/management/commands/loadstatus.py +++ b/backend/courses/management/commands/loadstatus.py @@ -72,6 +72,7 @@ def set_all_status(semester=None, add_status_update=False): print(f"{len(status_updates_out_of_sync)} status updates were out of sync.") print(status_updates_out_of_sync) + class Command(BaseCommand): help = "Load course status for courses in the DB. Conditionally adds StatusUpdate objects." diff --git a/backend/courses/management/commands/pathopendata.py b/backend/courses/management/commands/pathopendata.py index 637c48e9..4d34121e 100644 --- a/backend/courses/management/commands/pathopendata.py +++ b/backend/courses/management/commands/pathopendata.py @@ -16,51 +16,56 @@ import requests from urllib.parse import quote -def status_on_path_at_penn( - course_code, - path_at_penn_semester='202430' -): + +def status_on_path_at_penn(course_code, path_at_penn_semester="202430"): # Note: this api is actually unauthenticated as far as I can tell # so no cookies needed! headers = { - 'accept': 'application/json, text/javascript, */*; q=0.01', - 'accept-language': 'en-US,en;q=0.9', - 'content-type': 'application/json', - 'origin': 'https://courses.upenn.edu', - 'priority': 'u=1, i', - 'referer': 'https://courses.upenn.edu/', - 'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"', - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', - 'x-requested-with': 'XMLHttpRequest', + "accept": "application/json, text/javascript, */*; q=0.01", + "accept-language": "en-US,en;q=0.9", + "content-type": "application/json", + "origin": "https://courses.upenn.edu", + "priority": "u=1, i", + "referer": "https://courses.upenn.edu/", + "sec-ch-ua": '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": '"Windows"', + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "x-requested-with": "XMLHttpRequest", } params = { - 'page': 'fose', - 'route': 'search', - 'alias': course_code, + "page": "fose", + "route": "search", + "alias": course_code, } - data = quote(f'{{"other":{{"srcdb":"{path_at_penn_semester}"}},"criteria":[{{"field":"alias","value":"{course_code}"}}]}}') - response = requests.post('https://courses.upenn.edu/api/', params=params, headers=headers, data=data) + data = quote( + f'{{"other":{{"srcdb":"{path_at_penn_semester}"}},"criteria":[{{"field":"alias","value":"{course_code}"}}]}}' + ) + response = requests.post( + "https://courses.upenn.edu/api/", params=params, headers=headers, data=data + ) if response.ok: return { ("-".join(result["code"].split(" ")) + "-" + result["no"]): result["stat"] for result in response.json()["results"] } + def map_opendata_to_path(course_status): return "A" if course_status == "O" else "F" + def get_path_code(section_code): parts = section_code.split("-") return f"{parts[0]} {parts[1]}" + def find_diff(semester=None, add_status_update=False): if semester is None: semester = get_current_semester() @@ -82,10 +87,10 @@ def find_diff(semester=None, add_status_update=False): continue if any(course_term.endswith(s) for s in ["10", "20", "30"]): course_term = translate_semester_inv(course_term) - + if course_term != "2024C": continue - + course_map[section_code] = map_opendata_to_path(course_status) out_of_sync = [] @@ -105,10 +110,12 @@ def find_diff(semester=None, add_status_update=False): if path_status != section_status: out_of_sync.append((result, section_status, path_status)) - + for code, status1, status2 in out_of_sync: - print(f"{code} is out of sync. OpenData has status {status1} and Path has status {status2}.") - + print( + f"{code} is out of sync. OpenData has status {status1} and Path has status {status2}." + ) + class Command(BaseCommand): help = "Report the difference between OpenData and Path registrations." @@ -120,6 +127,4 @@ def handle(self, *args, **kwargs): root_logger = logging.getLogger("") root_logger.setLevel(logging.DEBUG) - find_diff( - semester=kwargs["semester"] - ) + find_diff(semester=kwargs["semester"])