diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a6711fb Binary files /dev/null and b/.DS_Store differ diff --git a/app.py b/app.py index 78c7b8f..10e99e1 100644 --- a/app.py +++ b/app.py @@ -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 = '' @@ -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' diff --git a/services/.DS_Store b/services/.DS_Store new file mode 100644 index 0000000..e5c0d32 Binary files /dev/null and b/services/.DS_Store differ diff --git a/services/movies/__init__.py b/services/movies/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/services/movies/__init__.pyc b/services/movies/__init__.pyc new file mode 100644 index 0000000..6bf0a06 Binary files /dev/null and b/services/movies/__init__.pyc differ diff --git a/services/movies/movies.py b/services/movies/movies.py new file mode 100644 index 0000000..381728b --- /dev/null +++ b/services/movies/movies.py @@ -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) diff --git a/services/movies/movies.pyc b/services/movies/movies.pyc new file mode 100644 index 0000000..62a8a61 Binary files /dev/null and b/services/movies/movies.pyc differ diff --git a/services/weather/weather.py b/services/weather/weather.py index 11e642c..cb4e7fb 100644 --- a/services/weather/weather.py +++ b/services/weather/weather.py @@ -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 '' @@ -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 ############################ @@ -48,3 +46,5 @@ def makeSpecial(): def eval(input): return getWeatherData(input) + +print eval("Boston")