Skip to content

Instantly share code, notes, and snippets.

@maemre
Created August 14, 2013 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maemre/6235587 to your computer and use it in GitHub Desktop.
Save maemre/6235587 to your computer and use it in GitHub Desktop.
A simple Python 3 script that finds some courses that are not conflicting with my schedule.
import urllib.request as u
import re
# Soppus' private web API
url = 'http://www.soppus.com/courseComplete.php'
# regular expression of the courses, I use only HTR311 for now
regex = re.compile(r'HTR311.*')
# Fetch the data and filter appropriate courses
c=[i.decode().split(' ') for i in u.urlopen(url).readlines() if regex.match(i.decode())]
# Discard TBA courses
c=filter(lambda x: x[1]!='TBA', c)
# My schedule
h = {
'M':set([3,4,5,6,7]),
'T':set([4]),
'W':set([1,2,3,5]),
'J':set([3,4,5,6,7,8]), # This is Thursday, Th makes processing harder so I replaced it with J
'F':set([5,6])
}
def dictise(x):
'''Creates a Python dictionary for course's schedule, like the one above'''
d={}
for i in range(len(x[1])):
if x[1][i] not in d:
d[x[1][i]]=[int(x[2][i])]
else:
d[x[1][i]].append(int(x[2][i]))
return d
def Th2J(x):
'''Converts 'Th' to 'J' for sake of easiness'''
x[1]=x[1].replace('Th','J')
return x
c=map(Th2J, c) # Convert Th->J
c=map(lambda x: (x, dictise(x)), c) # Parse schedule
for i in c:
x, d = i
ok = True
for k in d.keys():
# Check whether schedules intersect
if len(h[k].intersection(d[k])) > 0:
ok = False
break
# If there is no intersection then print the course
if ok:
x[1]=x[1].replace('J','Th') # some unrolling
print(' '.join(x)[:-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment