Esempio n. 1
0
def restaurant_route(r_id):
    yelp_inst = yelp.Yelp()
    twitter_inst = twitter.Twitter()
    tweets = []
    reset = False
    if request.method == 'POST':
        reset = True
    restaurant = yelp_inst.get_restaurant(r_id)
    tweets = twitter_inst.get_restaurant_tweets(restaurant, reset=reset)
    restaurant.price = restaurant.price * '$'
    if restaurant.hours == '':
        restaurant.hours = []
    else:
        restaurant.hours = restaurant.hours.split(',')
    if restaurant.categories == '':
        restaurant.categories = []
    else:
        restaurant.categories = restaurant.categories.split(',')
    if restaurant.business_info == '':
        restaurant.business_info = []
    else:
        restaurant.business_info = restaurant.business_info.split(',')
    if restaurant.similar == '':
        restaurant.similar = []
    else:
        restaurant.similar = restaurant.similar.split(',')
    return render_template('restaurant.html',
                           restaurant=restaurant,
                           tweets=tweets)
Esempio n. 2
0
def TestYelpUnhappy():
    data = None
    err = "failure"
    rest = mockRest(data, err)
    yelp = y.Yelp(rest)
    terms = ["test"]
    lat = 10
    long = 10
    result = yelp.getAmmenities(terms, lat, long, 10)
    if not result == None:
        fail("result should be None")
        return
    success()
Esempio n. 3
0
def TestYelpHappy():
    data = mockData.yelpBusinessSearchResponse
    rest = mockRest(data, None)

    yelp = y.Yelp(rest)
    terms = ["test"]
    lat = 10
    long = 10

    result = yelp.getAmmenities(terms, lat, long, 10)
    if result == None:
        fail("result should not be None")
        return
    success()
Esempio n. 4
0
 def test_restaurants(self):
     yelp_inst = yelp.Yelp()
     # test query
     restaurants, _ = yelp_inst.query('indian', 48104, 10000, 'distance')
     self.assertTrue(len(restaurants) > 0)
     found = False
     for restaurant in restaurants:
         if restaurant.id == 'K3EBuyhTBTAhR2-ImlrtJg' and restaurant.name == 'Madras Masala':
             found = True
     self.assertTrue(found)
     # test get_restaurant
     restaurant = yelp_inst.get_restaurant('K3EBuyhTBTAhR2-ImlrtJg')
     self.assertTrue(restaurant.rating == 4.0)
     self.assertTrue(restaurant.price == 2)
     self.assertTrue('Indian' in restaurant.categories.split(','))
     # check if in cache
     self.assertTrue(os.path.exists('cache/YELP.txt'))
     file_obj = open('cache/YELP.txt', 'r')
     file_data = file_obj.read()
     cache = json.loads(file_data)
     file_obj.close()
     self.assertTrue(restaurant.id in cache)
     print('Passed Yelp...')
Esempio n. 5
0
def home_route():
    error_msg = []
    if request.method == 'POST':
        yelp_inst = yelp.Yelp()
        ui_categories = ''
        ui_location = ''
        ui_radius = 10000
        ui_sort = 'distance'
        if 'ui_categories' in request.form and request.form[
                'ui_categories'].strip() != '':
            ui_categories = request.form['ui_categories']
        else:
            error_msg.append('Missing required field: Categories')
        if 'ui_location' in request.form and request.form['ui_location'].strip(
        ) != '':
            ui_location = request.form['ui_location']
        else:
            error_msg.append('Missing required field: Location')
        if 'ui_radius' in request.form:
            try:
                ui_radius = int(request.form['ui_radius'])
            except:
                error_msg.append(
                    'Error in field: Radius. Please enter a valid number between 1000 and 40000.'
                )
        if 'ui_sort' in request.form:
            ui_sort = request.form['ui_sort']
        # if no errors
        if len(error_msg) == 0:
            results, invalid = yelp_inst.query(ui_categories, ui_location,
                                               ui_radius, ui_sort)
            return render_template('index.html',
                                   error_msg=error_msg,
                                   invalid=invalid,
                                   restaurants=results)
    # get
    return render_template('index.html', error_msg=error_msg)
Esempio n. 6
0
def categories_route():
    categories = []
    yelp_inst = yelp.Yelp()
    categories = yelp_inst.categories
    return render_template('categories.html', categories=categories)
Esempio n. 7
0
import sys
sys.path += ['lib/']
sys.path += ['../../server/']
sys.path += ['../../server/lib-local']
sys.path += ['../../server/lib-both']

import yelp
import bing
import facebook

businesses = (yelp.Yelp().fetch_all('San Francisco, CA') +
              yelp.Yelp().fetch_all('Los Angeles, CA') +
              yelp.Yelp().fetch_all('New York, NY') + [])

fb_place_fields = 'id,about,category,category_list,company_overview,contact_address,cover,current_location,description,emails,fan_count,general_info,is_permanently_closed,location,link,name,phone,website,was_here_count'

show_good = True

for x in businesses:
    args = dict(type='place', q=x['name'], limit=1, fields=fb_place_fields)
    if x['coordinates']['latitude']:
        args['center'] = '%s,%s' % (x['coordinates']['latitude'],
                                    x['coordinates']['longitude'])
    results = facebook.search(**args)
    if 'data' not in results:
        raise Exception('Error on %s: %s' % (x['name'], results))
    if results['data']:
        result = results['data'][0]
        if 'website' in result:
            if show_good:
                print x['name'].encode(