This repository was archived by the owner on Apr 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (68 loc) · 2.38 KB
/
main.py
File metadata and controls
87 lines (68 loc) · 2.38 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import json
import requests
'''
GLOBAL VARIABLES
'''
fileName = "cupid-dump.json"
everyUnitFromCupid = json.load(open(fileName,'r'))
newUnitArray = []
reqHeaders = {
"Content-Type": "application/json"
}
def title_case(string):
if string == 'OFFICE OF THE DVC (GLOBAL ENGAGEMENT)':
return 'Office of the DVC (Global Engagement)'
elif string != '':
newString = string.split(' ')
for i in range(len(newString)):
newString[i] = newString[i][0].upper() + newString[i][1:].lower()
return ' '.join(newString)
else:
return None
def convertOfferings(string):
locations = {}
if(string != ''):
offerings = string.split('\n\n')
for i in range(len(offerings)):
currentOffering = (offerings[i].split(': '))
location = currentOffering[1].split(' ')
campus = location[0]
classType = location[1]
tp = currentOffering[0].split(' ')
year = (tp[0])
semester = ' '.join(tp[1:])
fullCode = year+"-"+semester
try:
if(classType == "ON-CAMPUS2017"):
classType = "ON-CAMPUS"
locations[campus][fullCode].append(classType)
except:
if(classType == "ON-CAMPUS2017"):
classType = "ON-CAMPUS"
locations[campus] = {}
locations[campus][fullCode] = [classType]
return locations
else:
return None
for unit in everyUnitFromCupid:
u = {}
u['unitCode'] = unit['Unit code']
u['unitName'] = unit['Title']
u['faculty'] = title_case(unit['Owning faculty'])
u['unitLevel'] = unit['Unit level']
u['teachingPeriods'] = convertOfferings(unit["Offering details (Future years only)"] + unit["Offering details (Current year only)"])
u['preqs'] = unit['Prerequisites']
u['coreqs'] = unit['Corequisites']
u['proh'] = unit['Prohibitions']
u['descrip'] = ' '.join(unit['Handbook synopsis'].split())
u['creditPoints'] = unit['Credit points']
u['scaBand'] = int(unit['Highest SCA band'])
u['eftsl'] = unit['Unit EFTSL']
u['levelType'] = unit["Undergraduate, Postgraduate or Both"]
u['unitObjectives'] = unit["Unit objectives"]
u['relevantAOS'] = unit["Unit objectives"]
u['studyLoad'] = unit["Workload requirements"]
u['assessment'] = unit["Assessment"]
r = requests.post("https://monplan-api-au-dev.appspot.com/api/units", data=json.dumps(u), headers=reqHeaders)
print(r.status_code, r.reason)
print(json.dumps(newUnitArray, indent=4, sort_keys=True))