Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def eval(cmd, input=None):
return shuttle.eval(cmd['args'])
elif cmd['service'] == 'W': ## Weather
return weather.eval(input)
elif cmd['courses'] == 'M': ## Courses
return courses.eval(input)
else:
return "ERROR 42: service not recognized"

Expand All @@ -33,6 +35,8 @@ def special(incoming):
body = laundry.special
elif incoming.upper() == "WEATHER":
body = weather.special
elif incoming.upper() == "COURSES":
body = courses.special
elif incoming.upper() == "DEMO":
## welcome/instructions
body = 'Thanks for using Harvard Now!\n'
Expand Down
3 changes: 2 additions & 1 deletion data.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@
{'service': 'S', 'args':{'endpoint': 'route', 'routeid': '4007272' , 'label': 'Barry\'s Corner Shuttle Route'}, 'tags':["BARRY'S",'BARRY', 'CORNER', 'SHUTTLE', 'ROUTE']},
{'service': 'S', 'args':{'endpoint': 'route', 'routeid': '4007610' , 'label': 'Quad Stadium Express Shuttle Route'}, 'tags':['QUAD', 'STADIUM', 'EXPRESS', 'SHUTTLE', 'ROUTE']},
{'service': 'S', 'args':{'endpoint': 'route', 'routeid': '4007650' , 'label': 'Allston Campus Express Shuttle Route'}, 'tags':['ALLSTON', 'CAMPUS', 'EXPRESS', 'SHUTTLE', 'ROUTE']},
{'service': 'W', 'args':{}, 'tags':['WEATHER']}
{'service': 'W', 'args':{}, 'tags':['WEATHER']},
{'service': 'M', 'args':{}, 'tags':['COURSES']}
]
1 change: 1 addition & 0 deletions services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from laundry import laundry
from shuttle import shuttle
from weather import weather
from courses import courses
Empty file added services/courses/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions services/courses/courses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import urllib2
from bs4 import BeautifulSoup

#############################
## Course Function ##
#############################

def getCourseInfo(input):
url = 'https://courses.harvard.edu/search?'
url += 'sort=score%20desc%2Ccourse_title%20asc&start=0&rows=25'
url += '&q=%s' % input
website = urllib2.urlopen(url)
soup = BeautifulSoup(website.read(), 'html.parser')

try:
instructors = soup.find(id='srl_instructor').text.encode('unicode-escape')
desc = soup.find(id='srl_description').text.encode('unicode-escape')
credits = soup.find_all('p')[2].text.encode('unicode-escape')
location = soup.find_all('p')[3].text.encode('unicode-escape')

body = 'Instructors: ' + instructors + '\n'
body += desc + '\n'
body += credits + '\n'
body += location + '\n'

except Exception, e:
print str(e)
return "Could not find course data. Are you sure you gave a proper course name?"

return body


def makeSpecial():
s = 'To get the info for a particular course, use the format \'courses course\'.'
return s

############################
## Top-Level ##
############################

## return list of valid laundry rooms
special = makeSpecial()

def eval(input):
return getCourseInfo(input)