def home():
    try:
        term = request.args.get('term')
        latlong_raw = request.args['latlong']
    except KeyError as unused_e:
        return make_response('404', 404)

    points = latlong_raw.strip('()').split(',')
    points = float(points[0]), float(points[1])

    latlong = (SFO_GEO[0] + points[0]) / 2.0, (SFO_GEO[1] + points[1]) / 2.0

    client = YelpClient(KEYS)
    api_resp = client.search_by_geo_coord(latlong=latlong,
                                          term=term,
                                          limit=LIMIT)
    return json.dumps(api_resp)
Example #2
0
def _dispatch_event(event):
    opentable = OpenTableClient()
    yelp = YelpClient(os.environ.get('YELP_CLIENT_ID'),
                      os.environ.get('YELP_CLIENT_SECRET'))

    name = event['currentIntent']['name']
    slots = event['currentIntent']['slots']
    if name == 'SearchRestaurant':
        category = slots['Category'].replace(' ',
                                             ',').replace(',', '+').replace(
                                                 '++', '+').lower()
        location = slots['Location'].replace(' ', ',').replace(',',
                                                               '+').replace(
                                                                   '++', '+')

        resp = yelp.search_restaurants(location, categories=category)

        attachments = []
        for business in resp:
            subtitle = ' '.join(business['location']['display_address'])
            attachments.append(
                _attachment(business['name'], business['url'], subtitle))

        response = _response('Close',
                             'Fulfilled',
                             'Search results for ' + category +
                             ' restaurants:',
                             attachments,
                             category=category,
                             location=location)
        print(json.dumps(response))
        return response
    elif name == 'BookRestaurant':
        restaurant = slots['Restaurant'].replace(' ', '+')
        location = event['sessionAttributes']['location']
        resp = opentable.search_restaurant(restaurant, city=location)
        print(json.dumps(resp))
        response = _response('Close', 'Fulfilled', 'Reservation created!')

        return response
 def __init__(self, yelp_api_keys):
     self.logger = logging.getLogger(self.__class__.__name__)
     self.client = YelpClient(yelp_api_keys)