Skip to content

Commit 5e58ee2

Browse files
committed
second batch of bios
1 parent 61191a5 commit 5e58ee2

File tree

5 files changed

+1385
-1108
lines changed

5 files changed

+1385
-1108
lines changed

scripts/generate_bios_json.py

Lines changed: 39 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -45,162 +45,98 @@ class Cols:
4545
"iamrejectingallcmpositionsthatididnotexplicitlyaccept"
4646
}
4747

48-
# global variables lmao
49-
exec_bios = {} # Written into src/data/bios/exec.json
50-
exec_roles = {} # Written into src/data/team/[SEMESTER].json
48+
# Global variables
49+
exec_bios = {}
50+
exec_roles = {}
5151

5252
def parse_bios(csv_path, master_roster_path):
5353
"""
5454
Reads bios from the given CSV, returning a dictionary of data keyed by emails.
5555
"""
56-
# Start by keying on email without periods so we can find duplicates easily
5756
people_by_email = {}
57+
5858
with open(EXEC_ROLE_PATH) as f:
5959
reader = csv.reader(f)
6060
for name, email, role in reader:
61-
email_no_dot = email.replace(".", "") if email else ""
62-
# We'll assume nobody is in multiple exec roles
63-
exec_roles[email_no_dot] = {
64-
"name": name,
65-
"imgUrl": "",
66-
"position": role
67-
}
68-
exec_bios[email_no_dot] = {
69-
"name": name,
70-
"role": role,
71-
"imgUrl": ""
72-
}
73-
61+
email_no_dot = email.replace(".", "").lower().strip() if email else ""
62+
exec_roles[email_no_dot] = {"name": name, "imgUrl": "", "position": role}
63+
exec_bios[email_no_dot] = {"name": name, "role": role, "imgUrl": ""}
64+
7465
with open(master_roster_path) as f:
7566
reader = csv.reader(f)
7667
for row in reader:
7768
name, email, role, preproc_course = row
7869
course = preproc_course.lower().replace(" ", "")
79-
email_no_dot = email.replace(".", "") if email else ""
80-
email_no_dot = email_no_dot.lower().strip()
70+
email_no_dot = email.replace(".", "").lower().strip()
71+
8172
if not role:
8273
print(f"=== WARNING: EMPTY ROLE IN MASTER ROSTER FOR {email.strip()} ===")
83-
if not course:
84-
if email_no_dot not in exec_bios:
85-
print(f"=== WARNING: EMPTY COURSE IN MASTER ROSTER FOR {email.strip()} AS {role} ===")
86-
continue # skip exec because they're already in exec roster
74+
if not course and email_no_dot not in exec_bios:
75+
print(f"=== WARNING: EMPTY COURSE IN MASTER ROSTER FOR {email.strip()} AS {role} ===")
76+
continue
8777
if role.lower() == "coordinator":
88-
continue # also skip coords because they're already in the exec roster
78+
continue
79+
8980
if email_no_dot not in people_by_email:
90-
people_by_email[email_no_dot] = {
91-
"name": name,
92-
"courses": {course: role},
93-
}
81+
people_by_email[email_no_dot] = {"name": name, "courses": {course: role}}
9482
else:
95-
obj = people_by_email[email_no_dot]
96-
obj["name"] = name
97-
obj["courses"][course] = role
98-
83+
people_by_email[email_no_dot]["courses"][course] = role
84+
9985
with open(csv_path) as f:
10086
reader = csv.DictReader(f)
10187
for row in reader:
10288
email = row[Cols.EMAIL]
103-
email_no_dot = email.replace(".", "") if email else ""
104-
email_no_dot = email_no_dot.lower().strip()
89+
email_no_dot = email.replace(".", "").lower().strip() if email else ""
10590
pref_name = row[Cols.PREF_NAME]
106-
use_pref_name = pref_name and not pref_name.isspace()
107-
name = row[Cols.NAME] if not use_pref_name else pref_name
91+
name = row[Cols.NAME] if not pref_name or pref_name.isspace() else pref_name
10892
photo_url = row[Cols.IMG_URL]
10993
bio = row[Cols.BIO]
11094
course = row[Cols.COURSE].lower().replace(" ", "").strip()
11195
role = row[Cols.ROLE]
11296
pronouns = row[Cols.PRONOUNS]
11397
web_url = row[Cols.WEB_URL]
11498

115-
if email_no_dot not in exec_roles:
116-
print(f"=== MISSING EXEC ROLE FOR {email_no_dot} ===")
117-
118-
def update(email_no_dot):
119-
# Assume the latest version of the bio is correct
120-
obj = people_by_email[email_no_dot]
121-
if use_pref_name:
122-
obj["name"] = name
123-
if pronouns and not pronouns.isspace():
124-
obj["pronouns"] = pronouns
125-
if course and not course.isspace():
126-
if "courses" not in obj:
127-
obj["courses"] = {}
128-
obj["courses"][course] = role
129-
if photo_url and not photo_url.isspace():
130-
obj["imgUrl"] = photo_url
131-
if bio and not bio.isspace():
132-
obj["details"] = bio
133-
if web_url and not web_url.isspace():
134-
obj["webUrl"] = web_url
135-
13699
if course in NORMALIZED_REJECTIONS:
137-
pass
138-
elif role == "Exec" or email_no_dot in exec_bios:
139-
# print(f"\t{name} for exec")
140-
exec_roles[email_no_dot]["imgUrl"] = photo_url
100+
continue
101+
102+
if email_no_dot in exec_bios:
103+
exec_roles[email_no_dot]["imgUrl"] = photo_url if photo_url and not photo_url.isspace() else ""
141104
exec_roles[email_no_dot]["pronouns"] = pronouns
142-
exec_bios[email_no_dot]["imgUrl"] = photo_url
105+
exec_bios[email_no_dot]["imgUrl"] = exec_roles[email_no_dot]["imgUrl"]
143106
exec_bios[email_no_dot]["pronouns"] = pronouns
144-
exec_bios[email_no_dot]["details"] = bio
145-
exec_bios[email_no_dot]["webUrl"] = web_url
146-
if email_no_dot in people_by_email:
147-
update(email_no_dot)
148-
# else:
149-
# print(f"=== SKIPPING EXEC {name} ===")
107+
exec_bios[email_no_dot]["details"] = bio if bio and not bio.isspace() else ""
108+
exec_bios[email_no_dot]["webUrl"] = web_url if web_url and not web_url.isspace() else ""
109+
print(f"Updated exec_bios for {email_no_dot}: {exec_bios[email_no_dot]}")
150110
else:
151-
# print(f"\t{name} for {course}")
152111
if email_no_dot not in people_by_email:
153-
people_by_email[email_no_dot] = {
112+
people_by_email[email_no_dot] = {"name": name, "pronouns": pronouns, "details": bio, "imgUrl": photo_url, "webUrl": web_url, "courses": {course: role}}
113+
else:
114+
obj = people_by_email[email_no_dot]
115+
obj.update({
154116
"name": name,
155117
"pronouns": pronouns,
156118
"details": bio,
157119
"imgUrl": photo_url,
158-
"webUrl": web_url,
159-
}
160-
if not course or course.isspace():
161-
print(f"=== NO COURSE FOUND FOR {name} ===")
162-
else:
163-
people_by_email[email_no_dot]["courses"] = {course: role}
164-
else:
165-
update(email_no_dot)
166-
# # 61B is doing its own form so I'm just hacking in a snippet here
167-
# with open("csvs/bios-61b.csv") as f:
168-
# reader = csv.DictReader(f)
169-
# for row in reader:
170-
# email = row["Email Address"]
171-
# email_no_dot = email.replace(".", "").lower().strip()
172-
# name = row["Preferred Name"]
173-
# photo_url = row["Photo"]
174-
# bio = row["Biography"]
175-
# # hardcode coords I guess
176-
# if name in ["Samantha Adams", "Ryan Nuqui"]:
177-
# exec_roles[email_no_dot]["imgUrl"] = photo_url
178-
# exec_bios[email_no_dot]["imgUrl"] = photo_url
179-
# exec_bios[email_no_dot]["details"] = bio
180-
# elif email_no_dot not in people_by_email:
181-
# print(f"=== NO ROLE WAS FOUND FOR 61B MENTOR {name}, SKIPPING FOR NOW ===")
182-
# else:
183-
# obj = people_by_email[email_no_dot]
184-
# obj["name"] = name
185-
# obj["imgUrl"] = photo_url
186-
# obj["details"] = bio
120+
"webUrl": web_url
121+
})
122+
obj["courses"][course] = role
187123

188-
# filter exec from people_by_email
189124
for email, bio in people_by_email.items():
190-
if "courses" in bio.keys() and "exec" in bio["courses"]:
125+
if "courses" in bio and "exec" in bio["courses"]:
191126
del bio["courses"]["exec"]
127+
192128
return people_by_email
193129

194-
195130
if __name__ == '__main__':
196131
print("Parsing bios...")
197132
people_by_email = parse_bios(BIOS_PATH, ROSTER_PATH)
198133
print("Dumping jsons...")
199-
# Write mentor bios
134+
200135
with open(DEST_PATH, "w") as outfile:
201136
json.dump(list(people_by_email.values()), outfile, indent=4)
202137
with open(f"src/data/team/{CURR_SEMESTER}.json", "w") as exec_file:
203138
json.dump(list(exec_roles.values()), exec_file, indent=4)
204139
with open(f"src/data/bios/exec.json", "w") as exec_bio:
205140
json.dump(list(exec_bios.values()), exec_bio, indent=4)
141+
206142
print("Done!")

0 commit comments

Comments
 (0)