-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcourse-intake.py
More file actions
73 lines (54 loc) · 1.91 KB
/
Copy pathcourse-intake.py
File metadata and controls
73 lines (54 loc) · 1.91 KB
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
import csv
import json
def main():
### FORMAT OF INPUT:
# CSV FORMAT: (ensure columns are named the same, verbatim)
# | number | advisor | facilitators | description |
# AS SUCH, YOUR CSV MUST HAVE A HEADER ROW WITH THE FOLLOWING:
# number,advisor,facilitators,description
# EXAMPLE CSV INPUT ROW FOR CMSC389E
# CMSC389E,Roger Eastman,"Akilesh Praveen,Dhanvee Ivaturi","A great class about Minecraft and Computer Science"
# IMPORTANT: Make sure you update 'counter' below to the most recent ID not used in catalog.js
# get STIC data file
courses_data = "/Users/aki/Documents/UMD/STICS/2021stics.csv"
try:
f = open(courses_data)
except FileNotFoundError as e:
print(e)
reader = csv.DictReader(f)
counter = 109
results = []
for row in reader:
row["id"] = counter
row["title"] = ""
row["website"] = "null"
row["department"] = row["number"][0:4]
row["number"] = row["number"][4:]
row["credits"] = 1
counter += 1
# reformat to give each facilitator an email address field as well
row["facilitators"] = [ {"name": x, "email": ""} for x in row["facilitators"].split(',') ]
raw_out = json.dumps(row, indent=2)
edited_out = remove_quotes(raw_out)
print(edited_out + ',')
def remove_quotes(input):
# remove unnecessary quotes from json output
to_change = {
'"name"':'name',
'"id"':'id',
'"advisor"':'advisor',
'"email"':'email',
'"description"':'description',
'"facilitators"':'facilitators',
'"number"':'number',
'"website"':'website',
'"title"':"title",
'"department"':'department',
'"credits"':'credits',
'"null"':'null'
}
for k,v in to_change.items():
input = input.replace(k,v)
return input
if __name__ == "__main__":
main()