-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsectionClass.py
More file actions
50 lines (44 loc) · 1.41 KB
/
sectionClass.py
File metadata and controls
50 lines (44 loc) · 1.41 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
def parse_minutes(time_str):
h, m = time_str[:-3].split(':')
if(time_str[-2:] == "PM"):
return int(h) * 60 + int(m) + 720
else:
return int(h) * 60 + int(m)
def parse_time(time_str, days):
if "TBA" in time_str or "TBA" in days:
return
times = []
dayInMinutes = 1440
dayDict = {
"M": 0,
"T": dayInMinutes,
"W": dayInMinutes * 2,
"R": dayInMinutes * 3,
"Th": dayInMinutes * 3,
"F": dayInMinutes * 4,
"S": dayInMinutes * 5,
"U": dayInMinutes * 6}
startTime, endTime = time_str.split('-')
startTime = parse_minutes(startTime)
endTime = parse_minutes(endTime)
if days.find("Th") == 1:
addDayMin = int(dayDict["Th"])
times.append((startTime+addDayMin, endTime+addDayMin))
days = days.replace("Th", "")
for day in days:
addDayMin = int(dayDict[day])
times.append((startTime+addDayMin, endTime+addDayMin))
return times
class Section:
def __init__(self, classObj):
self.crn = classObj[0]['CRN']
self.times = []
for oneClass in classObj:
tempTime = parse_time(oneClass['time'], oneClass['days'])
if tempTime:
for time in tempTime:
self.times.append(time)
def __str__(self):
return self.crn
def __repr__(self):
return self.crn