Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
shiva-menta committed Aug 29, 2024
1 parent 552fb2e commit dc75820
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions backend/courses/management/commands/loadstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
67 changes: 36 additions & 31 deletions backend/courses/management/commands/pathopendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 = []
Expand All @@ -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."
Expand All @@ -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"])

0 comments on commit dc75820

Please sign in to comment.