This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
175 lines (146 loc) · 7.01 KB
/
gui.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from tkinter import *
import tkinter.messagebox
import csv
import requests
import os
# 4260 is the code for Summer Quarter 2021.
# 4300 is the code for Fall Quarter 2021.
# 4320 is the code for Winter Quarter 2022
# 4340 is the code for Spring Quarter 2022.
# 4360 is the code for Summer Quarter 2022.
# 4400 is the code for Fall Quarter 2022.
"""
1. We first define a dictionary called quarterMap which maps the academic quarter to the quarter code.
2. We then define a function called get_courses which takes in the core code and the quarter code.
3. We then use the requests library to make a POST request to the SCU website.
4. We then use the json library to parse the response.
5. We then return the data from the response.
6. We then define a function called validateInput which takes in the user input.
"""
quarterMap = {
"Fall 2022": "4400",
"Summer 2022": "4360",
"Spring 2022": "4340",
"Winter 2022": "4320",
"Fall 2021": "4300",
"Summer 2021": "4260"
}
def get_courses(core, quarterCode):
payload = f"newcore={core}&maxRes=10000"
headers = {
"authority": "www.scu.edu",
"accept": "*/*",
"x-requested-with": "XMLHttpRequest",
"user-agent": os.getenv("USER_AGENT"),
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-gpc": "1",
"origin": "https://www.scu.edu",
"sec-fetch-site": "same-origin",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"accept-language": "en-US,en;q=0.9",
}
response = requests.request("POST", f"https://www.scu.edu/apps/ws/courseavail/search/{quarterCode}/ugrad", headers=headers, data=payload)
data = response.json()
return data
def validateInput():
quarter = input.get()
if (quarter == "Select academic quarter:"):
tkinter.messagebox.showinfo("Invalid Message Alert", "The field cannot be left empty!")
else:
tkinter.messagebox.showinfo("Success Message", "Successfully downloaded!")
courses = {}
# Core Codes
coreDict = {
"I_PTHAMS": "American Studies (Pathway)",
"I_PTHAE": "Applied Ethics (Pathway)",
"I_PTHB": "Beauty (Pathway)",
"I_PTHCHD": "Children, Family, & Society (Pathway)",
"I_PTHCINST": "Cinema Studies (Pathway)",
"I_PTHDEM": "Democracy (Pathway)",
"I_PTHDT": "Design Thinking (Pathway)",
"I_PTHFHP": "Feeding the World (Pathway)",
"I_PTHGGE": "Gender, Globalization & Empire (Pathway)",
"I_PTHGSB": "Gender, Sexuality & the Body (Pathway)",
"I_PTHGB": "Global Health (Pathway)",
"I_PTHHR": "Human Rights (Pathway)",
"I_PTHIS": "Islamic Studies (Pathway)",
"I_PTHJA": "Justice and the Arts (Pathway)",
"I_PTHLSJ": "Law & Social Justice (Pathway)",
"I_PTHLPOSC": "Leading People, Org & Soc Chng (Pathway)",
"I_PTHPS": "Paradigm Shifts (Pathway)",
"I_PTHPR": "Politics & Religion (Pathway)",
"I_PTHRPSI": "Race Place & Soc Inequalities (Pathway)",
"I_PTHS": "Sustainability (Pathway)",
"I_PTHDA": "The Digital Age (Pathway)",
"I_PTHVST": "Values Science Technology (Pathway)",
"I_PTHV": "Vocation (Pathway)",
"I_AW": "Advanced Writing",
"E_ARTS": "Arts",
"E_CE": "Civic Engagement",
"F_CTW1": "Critical Thinking and Writing 1",
"F_CTW2": "Critical Thinking and Writing 2",
"F_CI1": "Cultures and Ideas 1",
"F_CI2": "Cultures and Ideas 2",
"E_CI3": "Cultures and Ideas 3",
"E_DV": "Diversity",
"E_ETH": "Ethics",
"I_EL": "Experiential Learning for Social Justice",
"F_RTC1": "Religion Theology & Culture 1",
"E_RTC2": "Religion Theology & Culture 2",
"E_RTC3": "Religion Theology & Culture 3",
"E_STS": "Science Technology & Society",
"E_SOSC": "Social Science",
"E_ARTSPAR": "Partial Credit Arts",
"E_CEPAR": "Partial Credit Civic Engagement",
"E_STSPAR": "Partial Credit Engineering, Math, CS"
}
for core in coreDict:
print(f"Fetching {coreDict[core]} . . .")
# Fetch course data and add it to dict
data = get_courses(core, quarterMap.get(quarter))
for info in data["results"]:
if info["class_nbr"] in courses:
newCore = f"{courses.get(info['class_nbr']).get('core')}, {coreDict[core]}"
courses.get(info["class_nbr"]).update({"core": newCore})
else:
newCourse = {
"class": f"{info['subject']} {info['catalog_nbr']} ({info['class_nbr']})",
"description": info["class_descr"],
"core": coreDict[core],
"days-times": f"{info['mtg_days_1']} {info['mtg_time_beg_1']} - {info['mtg_time_end_1']}" if info["mtg_time_end_1"] != "" else "TBA",
"room": f"{info['mtg_facility_1'] or 'TBA' }",
"instructor": f"{info['instr_1'] or 'TBA' }",
"units": info["units_minimum"],
"seats": info["seats_remaining"] if int(info["seats_remaining"]) > 0 else "None",
}
courses.update({info["class_nbr"]: newCourse})
rows = ["CLASS", "DESCRIPTION", "CORES SATISFIED", "DAYS/TIMES", "ROOM", "INSTRUCTOR", "UNITS", "SEATS REMAINING"]
with open(f"scu_double_dips-{quarterMap.get(quarter)}.csv", "w") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(rows) # write header
for course in courses:
# Checking if there are multiple cores for a course.
if "," in courses.get(course).get("core"):
course_data = []
for data_point in courses.get(course):
course_data.append(courses.get(course)[data_point])
csv_writer.writerow([data_point for data_point in course_data]) # write each item
print(f"\n\n=== Finished fetching core requirements for {quarter}! ===\n\n")
if __name__ == "__main__":
root = Tk()
root.resizable(0,0)
root.geometry("500x350")
root.title("SCU Double Dip Courses Retriever")
label_0 = Label(root, text="SCU Core Double Dips", bg="#FF7C80", fg="white", width=20, font=("bold", 20))
label_0.place(x=90,y=53)
label_1 = Label(root, text="Quarter", width=20, font=("bold", 10))
label_1.place(x=70, y=180)
list1 = quarterMap.keys()
input = StringVar()
droplist = OptionMenu(root, input, *list1)
droplist.config(width=22)
input.set("Select academic quarter:")
droplist.place(x=240, y=180)
Button(root, text="Download", width=20, bg="#FF7C80", fg="white", command = validateInput).place(x=180,y=280)
root.mainloop()