-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.py
54 lines (46 loc) · 1.82 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from typing import Dict
from api import Session
from college_names import college_names
from parse import major_codes, major_plans
def get_plan_id(
session: Session, curriculum_ids: Dict[str, int], major_code: str, college_code: str
) -> int:
return session.get_degree_plans(curriculum_ids[major_code])[
f"{major_code}/{college_names[college_code]}"
]
if __name__ == "__main__":
import sys
from output import MajorOutput
from upload import MajorUploader, track_uploaded_curricula
session = MajorUploader()
mode = sys.argv[1]
major_code = sys.argv[2]
college_code = sys.argv[3] if len(sys.argv) >= 4 else None
year = 2021
with track_uploaded_curricula(year) as curricula:
if mode == "edit":
if college_code:
output = MajorOutput.from_json(
major_plans(year)[major_code],
session.get_curriculum(curricula[major_code]),
)
plan_id = get_plan_id(session, curricula, major_code, college_code)
session.edit_degree_plan(plan_id, output.output_json(college_code))
print(f"https://curricularanalytics.org/degree_plans/{plan_id}")
else:
session.edit_major(
curricula[major_code],
major_codes()[major_code],
year,
start_id=600,
log=True,
)
elif mode == "delete":
if college_code:
plan_id = get_plan_id(session, curricula, major_code, college_code)
session.destroy_degree_plan(plan_id)
else:
session.destroy_curriculum(curricula[major_code])
del curricula[major_code]
else:
raise ValueError(f"Unknown mode '{mode}'")