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 @@ -23,6 +23,8 @@ def eval(cmd, input=None):
return wordOfTheDay.eval()
elif cmd['service'] == 'MBTA':
return MBTA.eval(cmd['args'])
elif cmd['service'] == 'YELP':
return yelp.eval(input)
else:
return "ERROR 42: service not recognized"

Expand Down Expand Up @@ -52,6 +54,8 @@ def special(incoming):
body += 'Sending part of a name gives all information associated with that name.\n'
body += 'For example sending Quad will give information about the shuttle stop Quad and the shuttle'
body += 'route Quad Yard Express and sending Quincy laundry will give all the laundry rooms in Quincy.\n'
elif incoming.upper() == 'YELP':
body = yelp.special
return body

## main function
Expand Down
1 change: 1 addition & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,5 @@
{'service': 'MBTA', 'args': {'pg': ['orange/ONST', 'green/north']}, 'tags': ['MBTA', 'SUBWAY', 'T', 'SCHEDULE', 'LINE', 'ORANGE', 'NORTH', 'STATION', 'GREEN']},
{'service': 'MBTA', 'args': {'pg': ['blue/BGOV', 'green/gover']}, 'tags': ['MBTA', 'SUBWAY', 'T', 'SCHEDULE', 'LINE', 'BLUE', 'GOVERNMENT', 'CENTER', 'GREEN']},
{'service': 'MBTA', 'args': {'pg': ['orange/OHAY', 'green/haecl']}, 'tags': ['MBTA', 'SUBWAY', 'T', 'SCHEDULE', 'LINE', 'ORANGE', 'HAYMARKET', 'GREEN']},
{'service': 'YELP', 'args':{}, 'tags':['WEATHER']},
]
1 change: 1 addition & 0 deletions services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from weather import weather
from wordOfTheDay import wordOfTheDay
from MBTA import MBTA
from yelp import yelp
1 change: 1 addition & 0 deletions services/yelp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
special
1 change: 1 addition & 0 deletions services/yelp/f.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.yelp.com/search?find_desc=clover&find_loc=harvard%20yard
64 changes: 64 additions & 0 deletions services/yelp/yelp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import urllib2, urllib
import re
from bs4 import BeautifulSoup
from datetime import date
import calendar

def getYelpData(input) :
try:
#construct search url
url = 'https://www.yelp.com/search?find_desc=' + urllib.quote_plus(input.strip()) + '&find_loc=harvard%20yard'
hdr = {'User-Agent': 'Chrome'}
req = urllib2.Request(url,headers=hdr)
website = urllib2.urlopen(req)

#construct business url based on search results
tempurl = "https://www.yelp.com" + re.search("href=\"(/biz.+?)\"", website.read()).group(1)
hdr = {'User-Agent': 'Chrome'}
req = urllib2.Request(tempurl,headers=hdr)
website = urllib2.urlopen(req)

soup = BeautifulSoup(website.read(), 'html.parser')

#find business hours
bizhourstag = soup.find(class_ = "biz-hours")
bizhours = ""
try:
bizhours = (calendar.day_name[date.today().weekday()]
+ ": "
+ bizhourstag.findChildren("span", class_ = "nowrap", recursive=True)[0].string.strip()
+ " - "
+ bizhourstag.findChildren("span",class_ = "nowrap", recursive=True)[1].string.strip()
+ "\n")
except Exception,e:
pass

#find business address
addresstag = soup.find_all("address")
address = "" if (not addresstag or not addresstag[1]) else addresstag[1].string.strip() + "\n"

#find business name
nametag = (soup.find("h1", class_ = "biz-page-title embossed-text-white shortenough")
or
soup.find("h1", class_ = "biz-page-title embossed-text-white"))
name = "" if not nametag else nametag.string.strip() + "\n"

#find business phone
phonetag = soup.find_all(class_ = "biz-phone")
phone = "" if not phonetag else phonetag[0].string.strip() + "\n"

#construct return value.
body = (name or "") + (address or "") + (bizhours or "") + (phone or "") + tempurl
return body
except Exception, e:
print(e)
return "Unable to find business."



special = "Usage: yelp (business name). Provides phone number, yelp url, and today's hours."

def eval(input):
return getYelpData(input)

print getYelpData("cafe")