Skip to content

Commit

Permalink
Refactor request_degreeworks to management script
Browse files Browse the repository at this point in the history
  • Loading branch information
Clue88 committed Oct 1, 2023
1 parent 393c2ec commit 6153e4b
Show file tree
Hide file tree
Showing 4 changed files with 2,394 additions and 17 deletions.
17 changes: 17 additions & 0 deletions backend/degree/management/commands/import_degreeworks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.core.management.base import BaseCommand
import tqdm

from degree.models import DegreePlan, Requirement, Rule
from degree.utils.request_degreeworks import get_programs, degree_plans_of, audit, write_dp


class Command(BaseCommand):
help = "TODO: ADD HELP TEXT"

def handle(self, *args, **kwargs):
for year in range(2017, 2023 + 1):
print(year)
for program in get_programs(year=year):
print("\t" + program)
for degree_plan in tqdm(degree_plans_of(program), year=year):
write_dp(degree_plan, audit(degree_plan))
6 changes: 3 additions & 3 deletions backend/degree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DegreePlan(models.Model):
)

def __str__(self) -> str:
return f"DegreePlan: {self.program} {self.degree} in {self.major} with conc. {self.concentration} ({self.year})"
return f"{self.program} {self.degree} in {self.major} with conc. {self.concentration} ({self.year})"


class Requirement(models.Model):
Expand Down Expand Up @@ -103,7 +103,7 @@ class Requirement(models.Model):
)

def __str__(self) -> str:
return f"Requirement: {self.name} ({self.code}), min_cus={self.min_cus}, degree_plan={self.degree_plan}"
return f"{self.name} ({self.code}), min_cus={self.min_cus}, degree_plan={self.degree_plan}"


class Rule(models.Model):
Expand Down Expand Up @@ -168,4 +168,4 @@ class Rule(models.Model):
)

def __str__(self) -> str:
return f"Rule: {self.q}, min_num={self.min_num}, max_num={self.max_num}, min_cus={self.min_cus}, max_cus={self.max_cus}, requirement={self.requirement}"
return f"{self.q}, min_num={self.min_num}, max_num={self.max_num}, min_cus={self.min_cus}, max_cus={self.max_cus}, requirement={self.requirement}"
22 changes: 8 additions & 14 deletions backend/degree/scripts/request_degreeworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
s.headers.update(headers)


def audit(degree_plan: DegreePlan, timeout=30) -> dict:
"""
"""
def audit(degree_plan: DegreePlan, timeout=30):
payload = {
"studentId": env["PENN_ID"],
"isIncludeInprogress": True,
Expand Down Expand Up @@ -58,7 +55,7 @@ def audit(degree_plan: DegreePlan, timeout=30) -> dict:
return res.json()


def degree_plans_of(program_code: str, year: int=2023) -> list[DegreePlan]:
def degree_plans_of(program_code):
goals_payload = [
{
"id": "programCollection",
Expand All @@ -67,7 +64,7 @@ def degree_plans_of(program_code: str, year: int=2023) -> list[DegreePlan]:
"goals": [
{
"name": "catalogYear",
"selectedChoices": [str(year)],
"selectedChoices": ["2023"],
"ruleGoalCode": None,
"links": [],
},
Expand Down Expand Up @@ -384,7 +381,7 @@ def degree_plans_of(program_code: str, year: int=2023) -> list[DegreePlan]:
return degree_plans


def get_programs(timeout=30, year: int=2023) -> str:
def get_programs(timeout=30):
goals_payload = [
{
"id": "programCollection",
Expand All @@ -406,7 +403,7 @@ def get_programs(timeout=30, year: int=2023) -> str:
"source": "api/catalogYears",
"errorMessage": "",
"choices": [],
"selectedChoices": [str(year)],
"selectedChoices": ["2023"],
"ruleGoalCode": None,
"links": [],
},
Expand Down Expand Up @@ -2345,18 +2342,15 @@ def get_programs(timeout=30, year: int=2023) -> str:
return [program["key"] for program in res.json()[0]["goals"][1]["choices"]]


def write_dp(dp: DegreePlan, json: dict, dir: str | Path="degreeplans"):
with open(Path(
dir,
f"{dp.year}-{dp.program}-{dp.degree}-{dp.major}-{dp.concentration}"
)) as f:
def write_dp(dp: DegreePlan, json: dict, dir: str | Path = "degreeplans"):
with open(Path(dir, f"{dp.year}-{dp.program}-{dp.degree}-{dp.major}-{dp.concentration}")) as f:
json.dump(json, f, indent=4)


if __name__ == "__main__":
for year in range(2017, 2023 + 1):
print(year)
for program in get_programs(year=year):
print("\t" + program)
for degree_plan in tqdm(degree_plans_of(program), year=year):
write_dp(degree_plan, audit(degree_plan))

Loading

0 comments on commit 6153e4b

Please sign in to comment.