Skip to content

Commit bdcebd8

Browse files
committed
cleaned up code
1 parent 1937767 commit bdcebd8

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

analyze_citycollege.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,31 @@
88

99
find_cuny_hours = re.compile(r'(\d{1,2}(:\d\d)?)\s*-\s*((\d{1,2}(:\d\d)?)\s*(([AP]M)|NOON))')
1010

11-
if __name__ == "__main__":
12-
13-
soup = BeautifulSoup(open("citycollege/registrar.html"))
14-
15-
starts = []
16-
ends = []
17-
18-
coursetables = soup.findAll("table", {"class":"coursetable"})
19-
for course in coursetables:
20-
classtimes = course.findAll("td", text=re.compile(r'\d{1,2}:\d\d'))
21-
for c in classtimes:
22-
m = find_cuny_hours.search(c)
23-
if m:
24-
x = m.groups()
25-
start = x[0]
26-
end = x[2]
27-
starts.append(start)
28-
ends.append(end)
29-
print start,end
30-
else:
31-
print "No match found"
32-
print c
33-
print "found %(count)d total class times" % { "count": len(starts) }
34-
35-
# dividing up the classes we've found into different timeslots to count them
36-
timeslots = defaultdict(int)
37-
for i in range(len(starts)):
38-
timeslots[starts[i]+"-"+ends[i]] += 1
39-
40-
print(sorted(timeslots.items(), key=lambda x:x[1], reverse=True)[:10])
11+
soup = BeautifulSoup(open("citycollege/registrar.html"))
12+
13+
starts = []
14+
ends = []
15+
16+
coursetables = soup.findAll("table", {"class":"coursetable"})
17+
for course in coursetables:
18+
classtimes = course.findAll("td", text=re.compile(r'\d{1,2}:\d\d'))
19+
for c in classtimes:
20+
m = find_cuny_hours.search(c)
21+
if m:
22+
x = m.groups()
23+
start = x[0]
24+
end = x[2]
25+
starts.append(start)
26+
ends.append(end)
27+
print start,end
28+
else:
29+
print "No match found"
30+
print c
31+
print "found %(count)d total class times" % { "count": len(starts) }
32+
33+
# dividing up the classes we've found into different timeslots to count them
34+
timeslots = defaultdict(int)
35+
for i in range(len(starts)):
36+
timeslots[starts[i]+"-"+ends[i]] += 1
37+
38+
print(sorted(timeslots.items(), key=lambda x:x[1], reverse=True)[:10])

analyze_penn.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88
starts = []
99
ends = []
1010

11-
def parsefile(f):
11+
12+
# looping over every file in the directory
13+
for filename in os.listdir("pennregistrar/"):
14+
f = open("pennregistrar/"+filename, "r")
1215
for line in f:
1316
m = findhours.search(line)
1417
if m:
1518
x = m.groups()
16-
start =x[0]
19+
start = x[0]
1720
end = x[2]
1821
starts.append(start)
1922
ends.append(end)
2023
print start,end
21-
22-
# looping over every file in the directory
23-
for filename in os.listdir("pennregistrar/"):
24-
f = open("pennregistrar/"+filename, "r")
25-
parsefile(f)
2624
f.close()
2725

2826
print "found %(count)d total class times" % { "count": len(starts) }
@@ -32,4 +30,5 @@ def parsefile(f):
3230
for i in range(len(starts)):
3331
timeslots[starts[i]+"-"+ends[i]] += 1
3432

33+
#print timeslots.items()
3534
print(sorted(timeslots.items(), key=lambda x:x[1], reverse=True)[:10])

0 commit comments

Comments
 (0)