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
Binary file added .DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def eval(cmd, input=None):
return shuttle.eval(cmd['args'])
elif cmd['service'] == 'W': ## Weather
return weather.eval(input)
elif cmd['service'] == 'M':
return movies.eval(input)
else:
return "ERROR 42: service not recognized"

## list of services that need the user's input to work, not a command
def needsInput(cmd):
return cmd['service'] in ['W']
return cmd['service'] in ['W'] or cmd['service'] in ['M']

def special(incoming):
body = ''
Expand All @@ -33,6 +35,8 @@ def special(incoming):
body = laundry.special
elif incoming.upper() == "WEATHER":
body = weather.special
elif incoming.upper() == "MOVIES":
body = movies.special
elif incoming.upper() == "DEMO":
## welcome/instructions
body = 'Thanks for using Harvard Now!\n'
Expand Down
Binary file added services/.DS_Store
Binary file not shown.
Empty file added services/movies/__init__.py
Empty file.
Binary file added services/movies/__init__.pyc
Binary file not shown.
40 changes: 40 additions & 0 deletions services/movies/movies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import urllib2, urllib
import re
from bs4 import BeautifulSoup

#############################
## Weather Function ##
#############################

def getMovieData(input):
url = 'http://www.google.com/search?q=movies'
url += '+'+input
hdr = {'User-Agent': 'Chrome'}
req = urllib2.Request(url,headers=hdr)
website = urllib2.urlopen(req)
soup = BeautifulSoup(website.read(), 'html.parser')

try:
card = soup.find_all(class_ = 'fl _yxj')
body = ""
for i in card:
body += i.contents[0] + "\n"
except Exception, e:
print str(e)
return "Could not find movies data. Are you sure you gave a proper zipcode?"

return body

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

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

## return proper format to use for getting movies
special = makeSpecial()

def eval(input):
return getMovieData(input)
Binary file added services/movies/movies.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions services/weather/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def getWeatherData(input):

try:
card = soup.find(id='ires').find_all(class_='g')[0]

label = card.h3.text + '\n' if card.h3 is not None else ''

overview = card.img.attrs['title'] + '\n' if card.img is not None and card.img.has_attr('title') else ''
Expand All @@ -32,7 +31,6 @@ def getWeatherData(input):
except Exception, e:
print str(e)
return "Could not find weather data. Are you sure you gave a proper city name?"

return body

############################
Expand All @@ -48,3 +46,5 @@ def makeSpecial():

def eval(input):
return getWeatherData(input)

print eval("Boston")