Skip to content

Commit

Permalink
Final Review
Browse files Browse the repository at this point in the history
  • Loading branch information
shiva-menta committed Nov 11, 2024
1 parent 772e6b8 commit 6bf47a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 10 additions & 6 deletions backend/courses/management/commands/loadstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def set_all_status(semester=None, add_status_update=False, verbose=False):
statuses = registrar.get_all_course_status(semester)
if not statuses:
return
for status in tqdm(statuses):
statuses_out_of_sync = []
status_updates_out_of_sync = []

sections_to_update = []
statuses_out_of_sync = []
status_updates_out_of_sync = []

for status in tqdm(statuses):
section_code = status.get("section_id_normalized")
if section_code is None:
continue
Expand All @@ -47,12 +49,11 @@ def set_all_status(semester=None, add_status_update=False, verbose=False):
current_status = section.status

if current_status != course_status:
statuses_out_of_sync.append(section_code)
section.status = course_status
section.save()
sections_to_update.append(section)
statuses_out_of_sync.append(section_code)

if add_status_update and last_status_update.new_status != course_status:
status_updates_out_of_sync.append(section_code)
record_update(
section,
course_term,
Expand All @@ -61,6 +62,9 @@ def set_all_status(semester=None, add_status_update=False, verbose=False):
False,
json.dumps(status),
)
status_updates_out_of_sync.append(section_code)

Section.objects.bulk_update(sections_to_update, ["status"])

if verbose:
print(f"{len(statuses_out_of_sync)} statuses were out of sync.")
Expand Down
12 changes: 7 additions & 5 deletions backend/courses/management/commands/sync_path_status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import base64
import json
import logging
from typing import Dict, List, Tuple
Expand All @@ -16,6 +17,7 @@

path_semaphore = asyncio.Semaphore(25)
webhook_semaphore = asyncio.Semaphore(25)
auth = base64.standard_b64encode("webhook:password".encode("ascii"))


def map_path_to_opendata(course_status):
Expand Down Expand Up @@ -45,8 +47,8 @@ async def send_webhook_request(
async with webhook_semaphore:
await async_session.post(
url="https://penncoursealert.com/webhook/",
data=format_webhook_request_body(course, course_status, semester),
headers={"Content-Type": "application/json"},
data=json.dumps(format_webhook_request_body(course, course_status, semester)),
headers={"Content-Type": "application/json", "Authorization": f"Basic {auth.decode()}"},
)


Expand Down Expand Up @@ -83,7 +85,7 @@ async def get_department_path_status(
"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",
+ " (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
"x-requested-with": "XMLHttpRequest",
}

Expand Down Expand Up @@ -159,7 +161,7 @@ def resolve_path_differences(send_data_to_slack=False, verbose=False):
print(f"Inconsistent Courses: {inconsistent_courses}")

asyncio.run(send_webhook_requests(semester, inconsistent_courses, path_course_to_status))
if verbose:
if verbose and inconsistent_courses:
print("Sent updates to webhook.")

if send_data_to_slack and inconsistent_courses:
Expand All @@ -169,7 +171,7 @@ def resolve_path_differences(send_data_to_slack=False, verbose=False):
data=json.dumps(
{
"text": f"{len(inconsistent_courses)} inconsistent Course "
/ +"Statuses Resolved: {inconsistent_courses}"
+ f"Statuses Resolved: {inconsistent_courses}"
}
),
)
Expand Down

0 comments on commit 6bf47a3

Please sign in to comment.