Пример #1
0
def yelpSearch(term, location):
    yelp_api = YelpAPI (application.config['YELP_API_KEY'])
    result = yelp_api.search_query(term=term,location=location)
    response = jsonify(result)
    response.headers.add('Access-Control-Allow-Origin',
                         application.config['ALLOWED_DOMAIN'])
    return response
Пример #2
0
def return_restaurant(location_name):
    api_key = "###############"
    yelp_api = YelpAPI(api_key)
    # pprint(yelp_api.search_query(term='restaurant', location=location_name, sort_by='rating', limit=5))
    results = yelp_api.search_query(term='restaurant', location=location_name, limit=5)['businesses']
    print('connected')
    all_restaurant = []
    for i in range(5):
        name = ''
        display_phone = ''
        price = ''
        rating = ''
        url = ''
        if 'name' in results[i]:
            name = results[i]['name']
        if 'display_phone' in results[i]:
            display_phone = results[i]['display_phone']
        if 'price' in results[i]:
            price = results[i]['price']
        if 'rating' in results[i]:
            rating = results[i]['rating']
        if 'url' in results[i]:
            url = results[i]['url']

        temp_restaurant = Restaurant_info(name, display_phone, price, rating, url)
        # all_restaurant.append({'name':name, 'display_phone':display_phone,'price':price,'rating':rating,'url':url})
        all_restaurant.append(temp_restaurant)
    return all_restaurant
Пример #3
0
def interact_form():
    s = """<!DOCTYPE html>
<html>
<body>
<form action='/problem4form' method='POST'>
  <h1>Look for the best restaurants in your area!</h1>
  ENTER CITY HERE:<br>
  <input type="text" name="restaurants" value="">
  <br>
  <input type="submit" value="Submit">
</form>
</body>
</html>"""

    # Yelp api
    yelp_api = YelpAPI(yelp_info.client_id, yelp_info.client_secret)
    #list for the results
    restaurant_name = ""
    if request.method == 'POST':
        loc = request.form['restaurants']
        yelp = yelp_api.search_query(term='restaurant',
                                     location=loc,
                                     sort_by='rating',
                                     limit=3,
                                     radius=40000)
        for restaurant in yelp["businesses"]:
            restaurant_name = restaurant_name + ", " + restaurant['name']
        return s + '<br><br>' + "<h1>Try out these restaurants!</h1>" + restaurant_name[
            2:]
    else:
        return s
Пример #4
0
def get_info_from_api(consumer_key, consumer_secret, token, token_secret,
                      district, categories):

    yelp_api = YelpAPI(consumer_key, consumer_secret, token, token_secret)

    dictRest = {}

    offset = [0]

    for j in district:
        for category in categories:
            for k in offset:
                search_results = yelp_api.search_query(term=category,
                                                       location=j,
                                                       offset=k,
                                                       limit=20)
                list_Business = search_results["businesses"]
                if len(list_Business) <> 0:
                    for i in list_Business:
                        if i["location"].has_key("coordinate") and i.has_key(
                                "categories"):
                            busi_id = i["id"]
                            if busi_id not in dictRest.keys():
                                busi_info = {}
                                busi_info["name"] = i["name"]
                                busi_info["categories"] = i["categories"]
                                busi_info["rating"] = i["rating"]
                                busi_info["url"] = i["url"]
                                busi_info["longitude"] = i["location"][
                                    "coordinate"]["longitude"]
                                busi_info["latitude"] = i["location"][
                                    "coordinate"]["latitude"]
                                dictRest[busi_id] = busi_info

    return dictRest
Пример #5
0
def yelp_search(coords=(-122.4392, 37.7474)):
    yelp_api = YelpAPI(client_id, client_secret)
    search_results = yelp_api.search_query(categories='tacos',
                                           longitude=coords[0],
                                           latitude=coords[1],
                                           limit=10)
    return search_results
Пример #6
0
 def post(self, request):
     yelp_api = YelpAPI('4eeWvgRSP72tOmZaghWTvQ',
                        'K88plDw1UnwjACzBophf6Du578c',
                        'uKfMmBjcu1_JXCj5aS1o9foFOB8VpN4q',
                        'DRi5uRtvXpyXSRUxhf_8SaQ52LI')
     search_results = yelp_api.business_query(request.DATA.get('name'))
     return Response({'results': search_results.get('reviews')})
Пример #7
0
 def __init__(self):
     self.business_match = mongodb.db.business_match
     self.business_details = mongodb.db.business_details
     self.business_reviews = mongodb.db.business_reviews
     self.yelp_req = mongodb.db.yelp_request
     self.yelp_api = YelpAPI(app.config['YELP_API_KEY'])
     self.response = None
Пример #8
0
def food(jenni, input):
    if not hasattr(jenni.config, 'yelp_api_credentials'):
        return
    yelp_api = YelpAPI(jenni.config.yelp_api_credentials['consumer_key'], jenni.config.yelp_api_credentials['consumer_secret'], jenni.config.yelp_api_credentials['token'], jenni.config.yelp_api_credentials['token_secret'])

    location = input.group(2)

    if not location:
        jenni.say("Please enter a location.")
        return

    done = False
    max_offset = 5

    try:
        while not done:
            offset = random.randint(0, max_offset)
            response = yelp_api.search_query(category_filter="restaurants", location=location, limit=20, offset=offset)
            if len(response['businesses']) > 0:
                done = True
                jenni.say("How about, " + response['businesses'][random.randint(0, len(response['businesses']) - 1)]['name'] + "?")
            else:
                max_offset = offset - 1
    except YelpAPI.YelpAPIError:
        jenni.say("Invalid location!")
Пример #9
0
def process_search(request):
    form = request.GET
    # print(form)
    # googlemaps display
    googlemaps_url = f"https://www.google.com/maps/embed/v1/search?key={googlemap_key}&q={form['food_type']}+in+{form['location']}"
    request.session['search_url'] = googlemaps_url
    # print(googlemaps_url)
    # yelpapi call
    yelp_api = YelpAPI(yelp_key)
    businesses = yelp_api.search_query(term=form['food_type'],
                                       location=form['location'],
                                       sort_by='rating',
                                       limit=5)['businesses']
    # shape the response (name, image_url, url)
    # pprint.pprint(businesses)
    restaurant = {}
    result = []
    for business in businesses:
        for k, v in business.items():
            if k == "name" or k == "image_url" or k == "url":
                restaurant[k] = v
        result.append(restaurant)
        restaurant = {}
    request.session['top_restaurants'] = result
    context = {'googlemaps_url': googlemaps_url, 'top_restaurants': result}

    return render(request, 'roundtable/partials/rests_map.html', context)
Пример #10
0
def get_info_from_api(consumer_key, consumer_secret, token, token_secret, district, categories):
    
    yelp_api = YelpAPI(consumer_key, consumer_secret, token, token_secret)

    dictRest = {}
    
    offset = [0]

    for j in district:
        for category in categories:
            for k in offset:
                search_results=yelp_api.search_query(term = category,location = j,offset = k,limit = 20)
                list_Business=search_results["businesses"]
                if len(list_Business) <> 0:
                    for i in list_Business:
                        if i["location"].has_key("coordinate") and i.has_key("categories"):
                            busi_id=i["id"]
                            if busi_id not in dictRest.keys():
                                busi_info = {}
                                busi_info["name"] = i["name"]
                                busi_info["categories"] = i["categories"]
                                busi_info["rating"] = i["rating"]
                                busi_info["url"] = i["url"]
                                busi_info["longitude"] = i["location"]["coordinate"]["longitude"]
                                busi_info["latitude"] = i["location"]["coordinate"]["latitude"]
                                dictRest[busi_id] = busi_info

    return dictRest
Пример #11
0
def get_restaurants_seach():
    location = request.args.get('location')
    longitude = request.args.get('longitude')
    latitude = request.args.get('latitude')
    categories = request.args.get('categories')
    price = request.args.get('price')
    sort_by = request.args.get('sort_by')

    yelp_res = YelpAPI(API_KEY).search_query(location=location,
                                             longitude=longitude,
                                             latitude=latitude,
                                             categories=categories,
                                             price=price,
                                             sort_by=sort_by,
                                             limit=5)

    yelp_list = yelp_res["businesses"]
    biz_list = []

    user_id = session['user_id']
    user = crud.get_user_by_id(user_id)

    for idx in range(len(yelp_list)):
        yelp_id = yelp_list[idx]["id"]
        res = crud.get_restaurant_by_id(yelp_id)
        group_name = None
        if 'group_name' in request.cookies:
            group_name = request.cookies["group_name"]
        like = crud.get_like(user, res, group_name)
        biz = YelpAPI(API_KEY).business_query(id=yelp_id)
        biz_res = restaurant_from_yelp(biz, like, like_count=0)

        biz_list.append(biz_res)

    return jsonify({"businesses": biz_list})
Пример #12
0
def nearby_yelp(latitude, longitude):
    #from https://github.com/gfairchild/yelpapi
    #doc: http://www.yelp.com/developers/documentation/v2/search_api
    #Sort mode: 0=Best matched (default), 1=Distance, 2=Highest Rated
    
    yconsumer_key = '6IZDGF5Bck3MP6zU0lFgLQ'
    yconsumer_secret	= 'dZR4dJJpYUAETKH82yzv2nkXitM'
    ytoken = 'YtSoZfbmiWxfLg87GGoLUsC_wcx8wUtO'
    ytoken_secret = 'z9pDq7T0Pa_CwfQOMmF1XM4dhhQ'
    max_yelp_radius = 10000
    
    print YelpAPI(yconsumer_key, yconsumer_secret, ytoken, ytoken_secret)
    
    yelp_api = YelpAPI(yconsumer_key, yconsumer_secret, ytoken, ytoken_secret)
    llvar = str(latitude) + ',' + str(longitude)
    
    search_results = yelp_api.search_query(ll=llvar, limit=20, sort=0, radius_filter=rdist)
    
    #Make certain the farthest away places are still within your radius
    for i in search_results.get('businesses'):
        if i.get('distance') > max_yelp_radius:
            index = search_results.get('businesses').index(i) #find the index of it
            del search_results.get('businesses')[index]
            
    return search_results
Пример #13
0
class YelpScraper:
    """
    Right now it's basically a wrapper for YelpAPI object.

    Example
    y = YelpScraper('API KEY')
    res = y.get_pois(34.140940, -118.127974, 5000)  # Search near Pasadena
    biz_id = res['businesses'][0]['id']
    y.get_poi_features(biz_id)
    """
    def __init__(self, api_key):
        self.yelp = YelpAPI(api_key)

    def get_pois(self, latitude, longitude, radius):
        """
        Search Yelp for points of interest near the given latitude and
        longitude.
        https://www.yelp.com/developers/documentation/v3/business_search
        :param latitude: Decimal latitude.
        :param longitude: Decimal latitude.
        :param radius: Search radius in *meters*.
        """
        return self.yelp.search_query(latitude=latitude,
                                      longitude=longitude,
                                      radius=radius)

    def get_poi_features(self, yelpid):
        """
        Get details about a specific point of interest, given its Yelp ID.
        """
        return self.yelp.business_query(yelpid)
def yelpSearch(store,
               city="Edmonton"
               ):  #Search the store name on Yelp to find its classifications
    #my specific key
    yelp_api = YelpAPI(
        "BkeVvBepP5xWd8hfOi_Pud4wx3d1NWAx7XV_oopCygqKDNuJyE1MBr5TqGhNlBf1KM-cVcz05YsyTGkAkeVq73yTbwbER51fVxc9Qq4vGBhwtCQkjZvPP9LBkvNDXHYx"
    )
    #search yelp for the resturant
    op = yelp_api.search_query(term=store,
                               location=city,
                               sort_by='rating',
                               limit=5)
    title1 = ''
    title2 = ''
    title = []
    #find the descriptors of the buisness
    try:
        title1 = op['businesses'][0]['categories'][0]['title']
    except IndexError:
        print('Retailer not Recognized')
    try:
        title2 = op['businesses'][0]['categories'][1]['title']
    except IndexError:
        pass
    title.append(title1)
    title.append(title2)

    return title
Пример #15
0
def food(jenni, input):
    if not hasattr(jenni.config, 'yelp_api_credentials'):
        return
    yelp_api = YelpAPI(jenni.config.yelp_api_credentials['consumer_key'],
                       jenni.config.yelp_api_credentials['consumer_secret'],
                       jenni.config.yelp_api_credentials['token'],
                       jenni.config.yelp_api_credentials['token_secret'])

    location = input.group(2)

    if not location:
        jenni.say("Please enter a location.")
        return

    done = False
    max_offset = 5

    try:
        while not done:
            offset = random.randint(0, max_offset)
            response = yelp_api.search_query(category_filter="restaurants",
                                             location=location,
                                             limit=20,
                                             offset=offset)
            if len(response['businesses']) > 0:
                done = True
                jenni.say("How about, " +
                          response['businesses'][random.randint(
                              0,
                              len(response['businesses']) - 1)]['name'] + "?")
            else:
                max_offset = offset - 1
    except YelpAPI.YelpAPIError:
        jenni.say("Invalid location!")
Пример #16
0
def main():
    consumer_key = "z5lwUGdh0deaEbvRhUwCKw"
    consumer_secret = "Tq7QBqhKIKyNBlOEGYzJK0UrLHc"
    token = "QwkD6OQ_h3zslXmnTyoitk5vZqhSt8pv"
    token_secret = "95Oyv0QdB_v6ghyi87oe8AtPkBo"
    yelp_api = YelpAPI(consumer_key, consumer_secret, token, token_secret)
    args = {"term": "food", "location": "San Fransciso"}
    response = yelp_api.search_query(term = "food", location="Menlo Park")
    params = {"oauth_consumer_key": consumer_key,
              "oauth_token": token,
              "oauth_signature_method": "HMAC-SHA1",
              "oauth_signature": token_secret,
              "oauth_timestamp": int(time.time()),
              "oauth_nonce": uuid.uuid4()
              }
    #url = "https://api.yelp.com/v2/search?term=food&location=San+Francisco"
    #response = requests.get(url, params=params)
    rand = random.randint(0,len(response['businesses']))
    while rand < 4:
        if response['businesses'][rand]['rating'] >= 4:
            break
        else:
            rand = random.randint(0,len(response['businesses']))
    rec_rest = {'restaurant': response['businesses'][rand]['name'],
                'rating': response['businesses'][rand]['rating']}
    for i in range(len(response['businesses'])):
        if response['businesses'][i]['rating'] >= 4:
            print({'restaurant': response['businesses'][i]['name'],
                'rating': response['businesses'][i]['rating']})
        else:
            pass
    print('\n',rec_rest,sep='')
    def min_query(self, term, limit=5, category='', radius=None, location='washington, dc', sort=0, offset=0):
        '''A minimal query that returns a simple dictionary with the following key values.
        The values returned include name, phone, display phone, location, categories, yelp rating, yelp review count, a rating image url, yelp url, and yelp mobile url
        To simplify/minimize location, we return the neighborhood if available, else we return the city.'''
        # create YelpAPI object
        yelp_query = YelpAPI(self.consumer_key, self.consumer_secret, self.token, self.token_secret)

        response = yelp_query.search_query(term=term, category_filter=category, limit=limit, radius_filter=radius, location=location, sort=sort, offset=offset)
        print response
        min_response = []
        for entry in response['businesses']:
            if 'neighborhoods' in entry['location'].keys():
                location = entry['location']['neighborhoods'][0]
            elif 'city' in entry['location']:
                location = entry['location']['city']
            else:
                location = 'No neighborhood or city listed :('
            categories = ''
            if 'categories' in entry.keys():
                for value in entry['categories'][:-1]:
                    categories = categories + value[0] + ', '
                categories = categories + entry['categories'][-1][0]
            key_list = ['name', 'phone', 'display_phone', 'rating', 'review_count', 'rating_img_url', 'url', 'mobile_url']
            for key in key_list:
                if key not in entry.keys():
                    entry[key] = 'None'
            tmp_dict = {'name':entry['name'], 'phone':entry['phone'], 'display_phone':entry['display_phone'], 'location':location, 'categories':categories, 'rating':entry['rating'], 'review_count':entry['review_count'], 'rating_img_url':entry['rating_img_url'], 'url':entry['url'], 'mobile_url':entry['mobile_url']}
            min_response.append(tmp_dict)
        return min_response        
def filter_by_category(user_cuisine):
    # f = open('sample.json', 'w')

    # for category in processed_rest_data:
    #     if "restaurants" in restaurant["parents"]:

    # f = open('sample.json', 'r')
    # contents = f.read()
    # return json.loads(contents)

    # for cuisine in cuisines:
    # # params = get_search_parameters(cuisine)
    #     print cuisine
    yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

    try:
        print "trying %s....." % user_cuisine
        results = yelp_api.search_query(category_filter=user_cuisine, location="San Francisco, CA", limit=20)



        # results_string = json.dumps(results, indent=4)

        # f.write(results_string+'\n')
        # load_restaurants(results)
        print "%s worked!" % user_cuisine
        return results 
        

    except Exception, e:
        print user_cuisine, 'failed'
        print "error msg is:\n\n %s" % e
Пример #19
0
def get_data(address):
    """Get data for restaurants in campus area using Yelp"""
    # Arguments for search query
    search_term = 'restaurant*'
    campus_location = address
    spending_limits = '1, 2, 3'
    num_businesses = 50

    # Get and store data from the Yelp API
    yelp_api = YelpAPI(
        'Ew6EOoXyDZ2J5fGCqV4eRc7zhwDfwVmttmBpOI4AgIG4KIpgKFwZA9Bavy5rK6AonwB-nVXy4oBb1SU7'
        '-2Xp9xqKMxXpG7NYr4vDs6VkDpN4ITSH8Gn0PfNWxfxVW3Yx')
    results = yelp_api.search_query(term=search_term,
                                    location=campus_location,
                                    price=spending_limits,
                                    limit=num_businesses)

    # Retrieve necessary information and store
    biz_dict = {}

    for business in results['businesses']:
        biz_dict[business['name']] = {
            'rating': business['rating'],
            'popularity': business['review_count'],
            'price': business['price'],
            'distance': business['distance'],
            'url': business['url']
        }

    return biz_dict
Пример #20
0
def get_yelp(points):
    """
    Returns a list of dictionaries that contains name, address, and weighted rating of top restaurants along a route.

    Arguments
    ---------
    points is a list of dictionaries with keys being the time stamp and the values being the coordinates in a tuple

    Returns
    -------
    list of dictionaries with restaurant name, address, and weighted rating
        Removes duplicates, sorts by weighted rating
    """
    secret = open('app/yelp_key.txt', 'r')
    ykey = secret.read()
    secret.close()
    yelp_api = YelpAPI(ykey)

    response = []
    for key, value in points.items():
        response.append(
            yelp_api.search_query(term='restaurants',
                                  latitude=value[0],
                                  longitude=value[1],
                                  sort_by='rating',
                                  limit=5))
        time.sleep(.1)  # sleep .1 seconds to avoid yelp api limits
    initial = []
    for i in range(len(response)):
        for j in range(5):
            rating = response[i]['businesses'][j]['rating']
            review_count = response[i]['businesses'][j]['review_count']
            #Weighted formula, we set 50 as a moderate amount of reviews
            weighted = round(
                float(rating) + 5 *
                float(1 - math.pow(math.e, -review_count /
                                   MODERATE_NUMBER_OF_REVIEWS)), 3)
            if response[i]['businesses'][j]['location'][
                    'address1'] and not response[i]['businesses'][j][
                        'is_closed']:
                name = response[i]['businesses'][j]['name']
                address = response[i]['businesses'][j]['location'][
                    'address1'] + ", " + response[i]['businesses'][j][
                        'location']['city'] + ", " + response[i]['businesses'][
                            j]['location']['state'] + " " + response[i][
                                'businesses'][j]['location']['zip_code']
                initial.append({
                    'name': name,
                    'address': address,
                    'rating': weighted
                })
    #removes duplicates
    result = [
        dict(tupleized) for tupleized in set(
            tuple(name.items()) for name in initial)
    ]
    #sorts by weighted average
    result2 = sorted(result, key=lambda k: k['rating'], reverse=True)
    return (result2)
def get_categories_from_name_and_address(name, address):
    yelp_api = YelpAPI(MY_API_KEY)
    alias = get_alias_from_name_and_address(name, address)
    if alias == "":
        return []
    else:
        result = yelp_api.business_query(id=alias)
        return [c['alias'] for c in result['categories']]
Пример #22
0
    def __init__(self):
        api_key = get_secret('YELP', 'api_key')
        self.api = YelpAPI(api_key)

        events_connector = ConnectorEvent.query.filter(
            ConnectorEvent.connector_type == ExtractEvents.TYPE,
            ConnectorEvent.connector_event_id == ExtractEvents.ID).first()
        self.events = events_connector.data
Пример #23
0
def moreSearchResults():
    if len(resObjs) < 9:
        for objectNameMaker in range(5, 10):  #should prob put into a function
            resObjs.append('r' + str(objectNameMaker))
            resObjs[objectNameMaker] = restaurant()
    yelp_api = YelpAPI(api_key)
    yelpJson = yelp_api.search_query(term = form.query, location = form.location, distance = form.distance, price = form.price, limit = 10)
    initObjs(yelpJson, 10)
    return render_template('moreResults.html', resObjs = resObjs)
Пример #24
0
def businesses(city):
    CLIENT_ID = configKeys.ci
    CLIENT_SECRET = configKeys.cs
    api = YelpAPI(CLIENT_ID, CLIENT_SECRET)
    res = api.search_query(location=city,
                           sort_by='rating',
                           categories="arts",
                           limit=30)
    return res["businesses"]
Пример #25
0
    def __init__(self):
        self.BASE_URL = 'https://www.yelp.com/'
        #		auth =  Oauth1Authenticator(consumer_key=YOUR_CONSUMER_KEY,consumer_secret=YOUR_CONSUMER_SECRET,token=YOUR_TOKEN,token_secret=YOUR_TOKEN_SECRET)

        #		auth =  Oauth1Authenticator(consumer_key='pvImIXD6_9XDcw5TEBWdEw',consumer_secret='fBbKhobgly9fsjqnlsTNA5SyQI4',token='Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M',token_secret='u5YhqlY6ptEoleexrhQZmqM5vg8')
        #		client = Client(auth)
        self.yelp = YelpAPI('pvImIXD6_9XDcw5TEBWdEw',
                            'fBbKhobgly9fsjqnlsTNA5SyQI4',
                            'Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M',
                            'u5YhqlY6ptEoleexrhQZmqM5vg8')
def get_alias_from_name_and_address(name, address):
    yelp_api = YelpAPI(MY_API_KEY)
    result = yelp_api.search_query(term=name,
                                   location=address,
                                   sort_by='best_match',
                                   limit=1)
    try:
        return result['businesses'][0]['alias']
    except IndexError:
        return ""
Пример #27
0
	def __init__(self,params):
		self.BASE_URL = 'https://www.yelp.com/'
		self.yelp = YelpAPI('pvImIXD6_9XDcw5TEBWdEw','fBbKhobgly9fsjqnlsTNA5SyQI4','Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M','u5YhqlY6ptEoleexrhQZmqM5vg8')
		self.crawl_id = 0
		self.crawler_record = None
		self.site = None
		self.session = requests.Session()
		self.params = params
		self.keyword = params['term']+ ' '+params['location']
		self.count = 0
Пример #28
0
def process(id):
    yp = YelpAPI(
        'zmd9y3Q30Zj7Ekoh8sokT1bmzw4hWXNfzpjbnjSV5GXhX6v6gKslsx7T645Dm4rBMCv-x5ZKAM_0l7-FlFJS76ev43IWXnDcwyoOwIRVZh2SGyLne_jzL3-LHAbGXHYx'
    )
    response = yp.reviews_query(id)
    textArray = []
    for item in response['reviews']:
        textArray.append(item['text'])

    return str(sentiment.getSentiment(textArray))
Пример #29
0
def yelpJSON(label):
    label = label.encode('utf-8')
    yelp_api = YelpAPI(application.config['YELP_API_KEY'])
    result = yelp_api.business_query(label)
    reviews = yelp_api.reviews_query(label)
    result['review_list'] = reviews
    response = jsonify(result)
    response.headers.add('Access-Control-Allow-Origin',
                         application.config['ALLOWED_DOMAIN'])
    return response
Пример #30
0
def getDetailsFromAdress(adress):
    #adress = adress + " stockholm"
    yelp_api = YelpAPI(
        "MrRGPpo52MhH9Rhd2mYhqVTHUTolmcqQ1ekyXhAdh15ckOCdKeEPqgMvvOCBQM149OD5CpXMlg32NRseNdbtARSn_wErkvnAaLUXwZ0EBm4uhJXucT1ULSSrX9vwXXYx"
    )
    response = yelp_api.search_query(location=adress, radius=2000, limit=1)
    # print(response)
    latitude = response['region']['center']['latitude']
    longitude = response['region']['center']['longitude']
    pointsOfInterestsNearby = response['total']
    return (latitude, longitude, pointsOfInterestsNearby)
Пример #31
0
def getYelpData(phoneNums):
    """
  This function takes in a list of phone numbers and looks them up in Yelp
  Fusion using yelpapi. It then returns 2 dictionaries of the business'
  information and three pertinent user reviews of the business.

  param: phoneNums = List of phone numbers
  return: phoneDict = Dictionary mapping a phone number to a list.
                      list[0] = the business' rating
                      list[1] = the business' review count
                      list[2] = the business' url
  return: reviewDict = Dictionary mapping a phone number to a list of reviews
  (up to 3 reviews available, chosen by Yelp algorithm)
                      list[0] = the review's rating
                      list[1] = the review's text
                      list[2] = the review's time of creation (IN PACIFIC TIME)
  """

    yelp_api = YelpAPI(APIKEY)

    phoneDict = dict()
    reviewDict = dict()
    #lineNum = 1

    for phoneNum in phoneNums:
        #print(lineNum)
        response = yelp_api.phone_search_query(phone=str(phoneNum))
        #print(phoneNum)
        #pprint(response)

        #lineNum = lineNum + 1

        # If the phone number is listed in Yelp, store rating, review_count, url in
        # array mapped to phone number. Then, use the business-id field from
        # response to store 3 reviews in a separate list. Return both at end.
        if response['total'] != 0:
            business = response['businesses'][0]
            phoneDict[phoneNum] = [
                business['rating'], business['review_count'], business['url']
            ]

            # Get reviews using company id and store in reviewDict
            companyID = str(business['id'])
            reviewResponse = yelp_api.reviews_query(id=companyID)
            reviewList = reviewResponse['reviews']

            # Put a list of review information in reviewDict (mapped to phone number)
            for review in reviewList:
                reviewDict[phoneNum] = [
                    review['rating'], review['text'], review['time_created']
                ]

    return phoneDict, reviewDict
    def full_query(self, term, limit=5, category='', radius=None, location='washington, dc', sort=0):
        '''A full query that passes back the full JSON response from Yelp. For more information on 
        seacch and response values see http://www.yelp.com/developers/documentation/v2/search_api'''
        # create YelpAPI object
        yelp_query = YelpAPI(self.consumer_key, self.consumer_secret, self.token, self.token_secret)

        category=''
        limit=5
        radius=None
        offset = 0
        response = yelp_query.search_query(term=term, category_filter=category, limit=limit, radius_filter=radius, location=location, sort=sort, offset=offset)
        return response
Пример #33
0
def parseYelpData(places, heading="tel"):
    """
  This function takes in a list of businesses and looks them up by phone number
  in Yelp Fusion using yelpapi. It adds data about Yelp average rating of the
  business, the number of Yelp reviews, and the company's Yelp link to the 
  dictionary of the business. The function then returns the updated list of businesses.
  param: places list of businesses that have been scraped by the GoogleParser
  param: heading default to "tel", signifying the heading for the phone number data
         field of each business
  return: updated list of businesses, with these data fields added to each business:
          'yelp_rating', 'yelp_review_count', 'yelp_url','is_listed_yelp','is_claimed_yelp'
  """

    yelp_api = YelpAPI(APIKEY)

    for place in places:
        phoneNum = changeFormatTel(place[heading])
        if phoneNum == "":
            place['yelp_rating'] = ""
            place['yelp_review_count'] = ""
            place['yelp_url'] = ""
            place['is_listed_yelp'] = "0"
            place['is_claimed_yelp'] = "0"
            continue

        response = yelp_api.phone_search_query(phone=str(phoneNum))

        # If the phone number is listed in Yelp, add Yelp rating, review_count, and
        # yelpUrl to the dictionary of the business.
        if response['total'] != 0:
            business = response['businesses'][0]
            place['yelp_rating'] = strip(str(business['rating']))
            place['yelp_review_count'] = strip(str(business['review_count']))
            place['yelp_url'] = strip(str(business['url']))

            companyID = strip(str(business['id']))
            claimResponse = yelp_api.business_query(id=companyID)
            place['is_listed_yelp'] = "1"
            if claimResponse['is_claimed'] == True:
                place['is_claimed_yelp'] = "1"
            else:
                place['is_claimed_yelp'] = "0"

        else:
            place['yelp_rating'] = ""
            place['yelp_review_count'] = ""
            place['yelp_url'] = ""
            place['is_listed_yelp'] = "0"
            place['is_claimed_yelp'] = "0"

        # to avoid Yelp's error messages of too many queries per second
        time.sleep(1)
    return places
Пример #34
0
def get_yelp_data(params):
    api_key = 'm2Fz_n7pVC_-u3GTRpW392W_IpIWLL1e7ACybtxbOIulWzuhQ1U-mSWuCmNPZepBpWAzSq6kKmL9HF-rqMGYARNXy1y1016FU6_jEEFVHtivYJQlmpNxaHdBNnrdXXYx'
    yelp_api = YelpAPI(api_key, timeout_s=3.0)
    try:
        search_results = yelp_api.search_query(term=params['term'],
                                               location=params['location'],
                                               limit=params['limit'],
                                               offset=params['offset'])
    except:
        print('Exception')
        return None
    return search_results
Пример #35
0
def moreResults():
    yelp_api = YelpAPI(api_key)
    #ipAddress = "152.3.43.40"    #for testing locally
    ipAddress = getIP()
    locCoor = getLoc(ipAddress)
    if len(resObjs) < 9:
        for objectNameMaker in range(5, 10):  #should prob put into a function
            resObjs.append('r' + str(objectNameMaker))
            resObjs[objectNameMaker] = restaurant()
    NUM_REST = 10
    yelpJson = yelp_api.search_query(latitude = locCoor['lat'], longitude = locCoor['lon'], limit = 10)
    initObjs(yelpJson, 10)
    return render_template('moreResults.html', resObjs = resObjs)
Пример #36
0
    def test_uses_timeout(self, has_timeout, faker, mock_request, random_dict):
        url = faker.uri()
        mock_call = mock_request.get(url, json=random_dict)
        timeout_s = faker.random_int(1, 60) if has_timeout else None
        yelp = YelpAPI(faker.pystr(), timeout_s=timeout_s)

        assert 0 == mock_call.call_count

        resp = yelp._query(url)

        assert resp == random_dict
        assert 1 == mock_call.call_count
        assert timeout_s == mock_call.last_request.timeout
Пример #37
0
    def test_uses_timeout(self, has_timeout, faker, mock_request, random_dict):
        url = faker.uri()
        mock_call = mock_request.get(url, json=random_dict)
        timeout_s = faker.random_int(1, 60) if has_timeout else None
        yelp = YelpAPI(faker.pystr(), timeout_s=timeout_s)

        assert 0 == mock_call.call_count

        resp = yelp._query(url)

        assert resp == random_dict
        assert 1 == mock_call.call_count
        assert timeout_s == mock_call.last_request.timeout
Пример #38
0
def api():
    yelp_api = YelpAPI(
        "92b7FDwkewHE9-5Ii9ig1hrlYWRtuzGWzaCTSRialTUvjhx7IpvJvRI2KP2T71WiWxlc8eu4ASfYfdiQbPXAkKQvaQyIypoI9j9DXeqecgrgw78PM2CXiJe_JKrsW3Yx"
    )
    # args="?"
    # search_results = yelp_api.search_query(args)
    #print("10")
    response = yelp_api.phone_search_query(phone='+17189966288')
    #
    # print(response)
    # print("\n\n\n\n\n\n")
    # print (response['businesses'][0]['name'])

    return render_template('api.html', business=response)
Пример #39
0
class Yelp():

	def __init__(self):
		self.BASE_URL = 'https://www.yelp.com/'
#		auth =  Oauth1Authenticator(consumer_key=YOUR_CONSUMER_KEY,consumer_secret=YOUR_CONSUMER_SECRET,token=YOUR_TOKEN,token_secret=YOUR_TOKEN_SECRET)
	
#		auth =  Oauth1Authenticator(consumer_key='pvImIXD6_9XDcw5TEBWdEw',consumer_secret='fBbKhobgly9fsjqnlsTNA5SyQI4',token='Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M',token_secret='u5YhqlY6ptEoleexrhQZmqM5vg8')
#		client = Client(auth)
		self.yelp = YelpAPI('pvImIXD6_9XDcw5TEBWdEw','fBbKhobgly9fsjqnlsTNA5SyQI4','Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M','u5YhqlY6ptEoleexrhQZmqM5vg8')


	def getWebsite(self,url):
		response = requests.get(url)
		soup = BeautifulSoup(response.text)
		try:
			web = soup.find('div',{'class':'biz-website'}).find('a').text
			return web
		except:
			return url	


	def search(self,params):
		#response = client.search('San Francisco', **params)
		#print response.businesses
		response = self.yelp.search_query(term=params['term'],location=params['location'],limit=1)
		print self.getWebsite(response['businesses'][0]['url'])
Пример #40
0
	def __init__(self):
		self.BASE_URL = 'https://www.yelp.com/'
#		auth =  Oauth1Authenticator(consumer_key=YOUR_CONSUMER_KEY,consumer_secret=YOUR_CONSUMER_SECRET,token=YOUR_TOKEN,token_secret=YOUR_TOKEN_SECRET)
	
#		auth =  Oauth1Authenticator(consumer_key='pvImIXD6_9XDcw5TEBWdEw',consumer_secret='fBbKhobgly9fsjqnlsTNA5SyQI4',token='Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M',token_secret='u5YhqlY6ptEoleexrhQZmqM5vg8')
#		client = Client(auth)
		self.yelp = YelpAPI('pvImIXD6_9XDcw5TEBWdEw','fBbKhobgly9fsjqnlsTNA5SyQI4','Nj9xR2XNdp0yQzf6eJysd9AJkj-FFW4M','u5YhqlY6ptEoleexrhQZmqM5vg8')
Пример #41
0
def callYelp(location,term,limit):
    yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)
    response = yelp_api.search_query(term=term, location=location, sort=0, limit=limit)
    context_list = []

    for r in response['businesses']:
        single = {}
        single['term'] = term
        single['name'] = r['name']
        single['address'] =r['location']['display_address']
        single['link'] = r['url']
        single['lat'] = r['location']['coordinate']['latitude']
        single['lon'] = r['location']['coordinate']['longitude']
        if r['is_closed'] == "False":
            single['close'] = "CLOSE"
        else:
            single['close'] = "OPEN"
        context_list.append(single)
    return context_list
Пример #42
0
class Yelp(object):

    def __init__(self, longitude, latitude):
        self.client = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)
        self.longitude = str(longitude)
        self.latitude = str(latitude)
        print(self.latitude, self.longitude)

    def get_locations(self):
        return self.client.search_query(
            ll=self.latitude + ',' + self.longitude,
            limit=5)
    def YelpGain(self):
        from yelpapi import YelpAPI
        MY_CONSUMER_KEY = 'dae5HXBIXTb0ChnDZkzB3w'
        MY_CONSUMER_SECRET = 'qanTfPX5tMyh2hUFOMv-GgHgEUQ'
        MY_ACCESS_TOKEN = '60i6KZ_lUoOMuqZKb1yUsQ4EuRZweqS5'
        MY_ACCESS_SECRET = '0__YQm18_g2jUsMcbu6THu3edpA'

        yelp_api = YelpAPI(consumer_key=MY_CONSUMER_KEY,
                    consumer_secret=MY_CONSUMER_SECRET,
                    token=MY_ACCESS_TOKEN,
                    token_secret=MY_ACCESS_SECRET)

        yelpResult = {}
        index = 1
        response = yelp_api.search_query(term=info['yelp'], location='college station, tx', sort=2, limit=5)
        for business in response['businesses']:
            result = {}
            result['name'] = str(business['name'])
            result['id'] = str(business['id'])
            result['rating'] = str(business['rating'])+ "(" + str(business['review_count'])+'reviews' + ")"
            result['address'] = ', '.join(business['location']['display_address'])
            yelpResult[index] = result
            index = index + 1
        return yelpResult
Пример #44
0
# Scrapes a whole city from Yelp.

import argparse, csv, collections, geojson, ConfigParser, time
from yelpapi import YelpAPI
from shapely import geometry
import util
parser = argparse.ArgumentParser()
parser.add_argument('--neighborhoods_file', default='data/sffind_neighborhoods.json')
parser.add_argument('--config_file', default='config.txt')
parser.add_argument('--output_file', default='yelp_results.json')
args = parser.parse_args()

config = ConfigParser.ConfigParser()
config.read('config.txt')
yelp_api = YelpAPI(config.get('yelp', 'consumer_key'),
        config.get('yelp', 'consumer_secret'), config.get('yelp', 'token'),
        config.get('yelp', 'token_secret'))

# results = yelp_api.search_query(term='coffee', location='Noe Valley, San Francisco, CA')
# https://www.yelp.com/developers/documentation/v2/search_api
num_results_so_far = 0
while True:
    results = yelp_api.search_query(category_filter='coffee',
        location='San Francisco, CA', offset=num_results_so_far)
    print results['total']
    for business in results['businesses']:
        if business['is_closed']:
            print "Not including, permanently closed: %s" % business['name']
            continue
        print business['name']
        print business['location']['coordinate']
Пример #45
0
from yelpapi import YelpAPI
from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET

yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

# Example search by bounding box and category. See
# http://www.yelp.com/developers/documentation/v2/all_category_list
# for an official list of Yelp categories. The bounding box definition
# comes from
# http://isithackday.com/geoplanet-explorer/index.php?woeid=12587707.

print('***** 5 bike rentals in San Francisco county *****')

response = yelp_api.search_query(category_filter='bikerentals', bounds='37.678799,-123.125740|37.832371,-122.356979', limit=5)
    
for business in response['businesses']:
    print('{}\n\tYelp ID: {}\n\trating: {} ({} reviews)\n\taddress: {}'.format(business['name'], business['id'], business['rating'],
                                                                               business['review_count'], business['location']['display_address']))
Пример #46
0
import time

client = MongoClient('localhost', 27017)
db = client.yelp_maryland
yelp_results_collection = db.yelp_results
argparser = argparse.ArgumentParser(description='Example Yelp queries using yelpapi. Visit https://www.yelp.com/developers/manage_api_keys to get the necessary API keys.')
argparser.add_argument('--consumer_key', type=str, help='Yelp v2.0 API consumer key')
argparser.add_argument('--consumer_secret', type=str, help='Yelp v2.0 API consumer secret')
argparser.add_argument('--token', type=str, help='Yelp v2.0 API token')
argparser.add_argument('--token_secret', type=str, help='Yelp v2.0 API token secret')
args = argparser.parse_args()
args.consumer_key = "R5P_xyFZ-bwmmv8wf8opCQ"
args.consumer_secret = "YIDTvnHGL7ca0t9GlxEgCYtnQbo"
args.token = "gMilIig9VdyrSVnrqZBoTkFnARB4WQol"
args.token_secret = "AlieRCAbn28ppTXt_dteyDHdRDk"
yelp_api = YelpAPI(args.consumer_key, args.consumer_secret, args.token, args.token_secret)


#attrs=BusinessParking.garage,BusinessParking.lot,BusinessParking.validated
#sortby=review_count

yelp_results_collection.remove()
#response = yelp_api.search_query(term='alcohol', location='Montgomery County, MD', sort=2, limit=20, offset=0)
#response2 = yelp_api.search_query(term='alcohol', location='Montgomery County, MD', sort=2, limit=20, offset=20)
#response_code = yelp_results_collection.insert(response)
#response_code2 = yelp_results_collection.insert(response2)

BaseLat = 38.9
BaseLon = -77.4

lat_intervals = [float(i) / 10 for i in xrange(5)]
Пример #47
0
from yelpapi import YelpAPI
from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET

yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

# Example business query. Look at
# http://www.yelp.com/developers/documentation/v2/business for more
# information.

print("***** selected reviews for Amy's on 6th St. *****")

business = yelp_api.business_query(id='amys-ice-creams-austin-3')

for review in business['reviews']:
    print('rating: {}\nexcerpt: {}\n'.format(review['rating'], review['excerpt']))

Пример #48
0
from yelpapi import YelpAPI
import pandas as pd
consumer_key = 'PnHvincoddn76xfpm3LhLg'
consumer_secret = 'PGmBEyjY0dKu1jzYkJr2Mxe2SCs'
token = 'Xo8UWIL1CdyTxn-cX-XYbxsAXQOpgfYz'
token_secret = '1J60nMB-wGTsLyNOyGkY9EZfMFM'
yelp_api = YelpAPI(consumer_key,consumer_secret,token,token_secret)
#search_results = yelp_api.search_query()
columns = ['bars','restaurants','laundry','pizza','hospitals','coffee','boutique','clothing','education','arts']
#zip_code = ['10453','10458','10451','10454','10463','10466','10461','11212','11209','11204','11234','11223','11201','11203','11207','11211','11220','11206','10026','10001','10029','10010','10012','10004','10002','10021','10023','10031','11361','11354','11365','11412','11101','11374','11691','11004','11414','11368','10301','10314']
zip_code = [10001, 10002, 10003, 10004, 10005, 10006, 10007, 10009, 10010, 10011, 10012, 10013, 10014, 10016, 10017, 10018, 10019, 10020, 10021, 10022, 10023, 10024, 10025, 10026, 10027, 10028, 10029, 10030, 10031, 10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10044, 10065, 10069, 10075, 10103, 10110, 10111, 10112, 10115, 10119, 10128, 10152, 10153, 10154, 10162, 10165, 10167, 10168, 10169, 10170, 10171, 10172, 10173, 10174, 10177, 10199, 10271, 10278, 10279, 10280, 10282, 10301, 10302, 10303, 10304, 10305, 10306, 10307, 10308, 10309, 10310, 10311, 10312, 10314, 10451, 10452, 10453, 10454, 10455, 10456, 10457, 10458, 10459, 10460, 10461, 10462, 10463, 10464, 10465, 10466, 10467, 10468, 10469, 10470, 10471, 10472, 10473, 10474, 10475, 11004, 11005, 11101, 11102, 11103, 11104, 11105, 11106, 11109, 11201, 11203, 11204, 11205, 11206, 11207, 11208, 11209, 11210, 11211, 11212, 11213, 11214, 11215, 11216, 11217, 11218, 11219, 11220, 11221, 11222, 11223, 11224, 11225, 11226, 11228, 11229, 11230, 11231, 11232, 11233, 11234, 11235, 11236, 11237, 11238, 11239, 11351, 11354, 11355, 11356, 11357, 11358, 11359, 11360, 11361, 11362, 11363, 11364, 11365, 11366, 11367, 11368, 11369, 11370, 11371, 11372, 11373, 11374, 11375, 11377, 11378, 11379, 11385, 11411, 11412, 11413, 11414, 11415, 11416, 11417, 11418, 11419, 11420, 11421, 11422, 11423, 11424, 11425, 11426, 11427, 11428, 11429, 11430, 11432, 11433, 11434, 11435, 11436, 11451, 11691, 11692, 11693, 11694, 11697]
d = {}
for i in columns:
	count = d.setdefault(i, {})
	for j in zip_code:
		count = d[i].setdefault(j, 0)
		business_results = yelp_api.search_query(term = i,location = j, radius_filter = 1000)
		
		rating = 0
		num = 0
		for k in business_results['businesses']:
			try:
				if k['review_count']>500:
					rating += (k['rating']/float(5))*3 + 2
				else:
					rating += (k['rating']/float(5))*3 + (k['review_count']/float(500))*2
				#print k['name'],k['rating'],k['review_count'],k['location']['postal_code'],k['location']['neighborhoods']
			except:
				continue
		rating = rating/float(20)
		print i,j
Пример #49
0
"""
    Example call:
        ./examples.py "[API Key]"
"""

from yelpapi import YelpAPI
import argparse
from pprint import pprint

argparser = argparse.ArgumentParser(description='Example Yelp queries using yelpapi. '
                                                'Visit https://www.yelp.com/developers/v3/manage_app to get the '
                                                'necessary API keys.')
argparser.add_argument('api_key', type=str, help='Yelp Fusion API Key')
args = argparser.parse_args()

yelp_api = YelpAPI(args.api_key)

"""
    Example search by location text and term. 
    
    Search API: https://www.yelp.com/developers/documentation/v3/business_search
"""
print('***** 5 best rated ice cream places in Austin, TX *****\n{}\n'.format("yelp_api.search_query(term='ice cream', "
                                                                             "location='austin, tx', sort_by='rating', "
                                                                             "limit=5)"))
response = yelp_api.search_query(term='ice cream', location='austin, tx', sort_by='rating', limit=5)
pprint(response)
print('\n-------------------------------------------------------------------------\n')


"""
Пример #50
0
from yelpapi import YelpAPI
import pysolr
import json
import collections
import dictlitestore

yelp_api =YelpAPI('a5oBT4RnnHpt6rtHQWsGYg','61UpHpxNDVJfpACumIIJNIR2nJ8','-PlfjeTyjnMSGP67pQbopdxJ-lXE70Bn','ewGlo-jkCt0LpNYphzr2SxaEtCY')
neighborhoods = ['Ang Mo Kio','Arab Street','Bedok North', 'Bishan', 'Boat Quay', 'Boon Keng', 'Boon Lay','Bras Brasah','Bugis','Bukit Timah','Changi','Chinatown','Choa Chu Kang','City Hall','Clarke Quay','Clementi','Dhoby Ghaut','Eunos','Farrer Park','Geylang','Harbourfront','Holland Village','Hougang','Kallang','Katong','Lavender','Macpherson','Marine Parade','Newton','Novena','Orchard','Pasir Ris','Raffles Place','Serangoon','Somerset','Tampines','Thomson','Toa Payoh','Woodlands','Yio Chu Kang','Yishun']
#neighborhoods = ['Lavender','Macpherson','Marine Parade','Newton','Novena','Orchard','Pasir Ris','Raffles Place','Serangoon','Somerset','Tampines','Thomson','Toa Payoh','Woodlands','Yio Chu Kang','Yishun']

#solr = pysolr.Solr('http://localhost:8983/solr/', timeout=10)


row = 0
print len(neighborhoods)
#resultsDict = []
with dictlitestore.DictLiteStore('sports.db', 'sportslistings') as bucket:
    #results = yelp_api.search_query(location='singapore', category_filter='shopping')
    #print results['businesses'][0]
    #print len(results['businesses'])
    #bucket.store(results['businesses'][0])

    for location in neighborhoods:
        search_results = yelp_api.search_query(location=location, category_filter='active', cc='SG')
        #print type(search_results)
        #print json.dumps(search_results['businesses'])
        print location
        print "-------------------------------------------------------"

        totalResults = search_results['total']
        for x in range (0, min(50, totalResults/20)):
# Answer to Challenge 1: Change your search in some way described in the API
# documentation (e.g., use a category filter) 
#
# I've changed this to print ice cream places in Seattle using the category
# filter. I used the term "icecream" which I found documented on this page in
# the API documentation:
#
# https://www.yelp.com/developers/documentation/v2/all_category_list

from yelpapi import YelpAPI
from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET

yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

# Example search by location text and term. Take a look at
# http://www.yelp.com/developers/documentation/v2/search_api for
# the various options available.

print('***** 5 best rated ice cream places in Seattle, WA *****')

response = yelp_api.search_query(category_filter='icecream', location='seattle, wa', sort=2, limit=5)

print('region center (lat,long): {},{}\n'.format(response['region']['center']['latitude'], response['region']['center']['longitude']))

for business in response['businesses']:
    print('{}\n\tYelp ID: {}\n\trating: {} ({} reviews)\n\taddress: {}'.format(business['name'], business['id'], business['rating'], business['review_count'], business['location']['display_address']))

Пример #52
0
def main():
    yelp_api = YelpAPI(login_data['yelp_consumer_key'],
                       login_data['yelp_consumer_secret'],
                       login_data['yelp_token'],
                       login_data['yelp_token_secret'])

    zip_codes = [row.zip_code for row in session.query(ZipCode).all()]

    current_month = datetime.date.today().month
    current_rows = session.query(YelpAPIDb).filter(extract('month', YelpAPIDb.date_created) == current_month).all()
    current_rows = [row.as_dict() for row in current_rows]
    existing_zip_codes = [row['zip_code'] for row in current_rows]
    remaining_zip_codes = [zip_code for zip_code in zip_codes if zip_code not in existing_zip_codes]

    category_list = ["cafes",
                     "newamerican",
                     "indpak",
                     "italian",
                     "japanese",
                     "thai"]

    for i, zip_code in enumerate(remaining_zip_codes):
        zip_code_results = []
        for category in category_list:
            offset = 0
            total_count = 21
            results_per_query_limit = 20
            business_counter = 1
            remaining_count = 1

            LOGGER.info("Extracting {} restaurants from zip code {} ({} out of {})".format(category, zip_code, i,
                                                                                           len(remaining_zip_codes)))
            while remaining_count > 0:
                try:

                    search_results = yelp_api.search_query(location=zip_code,
                                                           category_filter=category, sort=0, limit=20,
                                                           offset=offset)
                    total_count = search_results['total']
                except YelpAPI.YelpAPIError as e:
                    print e
                    break
                if search_results['total'] == 0:
                    session.merge(YelpAPIDb(zip_code=zip_code, date_created=datetime.date.today(), avg_rating=None,
                                            business_count=0))
                    session.commit()
                    break
                for business in search_results['businesses']:
                    if is_business_valid(business, zip_code):
                        print "{} out of {} businesses".format(business_counter, total_count)
                        zip_code_results.append({"zip_code": zip_code,
                                                 "rating": business['rating'],
                                                 "review_count": business["review_count"]})
                    business_counter += 1

                remaining_count = total_count - business_counter
                offset += results_per_query_limit

        if zip_code_results:
            total_review_count = sum([business['review_count'] for business in zip_code_results])
            zip_code_avg_rating = sum(
                [business['rating'] * business['review_count'] for business in zip_code_results]) / total_review_count
            row = YelpAPIDb(zip_code=zip_code, date_created=datetime.date.today(), avg_rating=zip_code_avg_rating,
                            business_count=len(zip_code_results))
            session.merge(row)
            session.commit()
        else:
            session.merge(
                YelpAPIDb(zip_code=zip_code, date_created=datetime.date.today(), avg_rating=None, business_count=0))
            session.commit()
    session.close()
# Answer to Challenge 6: What is the highest rated falafel place in Seattle?

from yelpapi import YelpAPI
from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET

yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

# Example search by location text and term. Take a look at
# http://www.yelp.com/developers/documentation/v2/search_api for
# the various options available.

response = yelp_api.search_query(term='falafel', location='seattle, wa', sort=2, limit=1)

for business in response['businesses']:
    print('{}\n\trating: {} ({} reviews)'.format(business['name'], business['rating'], business['review_count']))

Пример #54
0
from yelpapi import YelpAPI
yelp_api =YelpAPI('a5oBT4RnnHpt6rtHQWsGYg','61UpHpxNDVJfpACumIIJNIR2nJ8','-PlfjeTyjnMSGP67pQbopdxJ-lXE70Bn','ewGlo-jkCt0LpNYphzr2SxaEtCY')
neighborhoods = ['Alexandra', 'Ang Mo Kio', 'Ann Siang Hill', 'Arab Street', 'Bayfront', 'Bedok North', 'Bedok Reservoir', 'Bedok South', 'Bencoolen', 'Bishan', 'Boat Quay', 'Boon Keng', 'Boon Lay','Bras Brasah','Buangkok','Bugis','Bukit Batok','Bukit Panjang','Bukit Timah','Changi','Chinatown','Choa Chu Kang','City Hall','Clarke Quay','Clementi','Dempsey Hill','Dhoby Ghaut','Dover','Duxton Hill','Eunos','Farrer Park','Geylang','Ghim Moh','Harbourfront','Holland Hill','Holland Village','Hougang','Joo Chiat','Jurong','Jurong Island','Kallang','Katong','Kembangan','Kent Ridge','Keppel','Labrador Park','Lavender','Lim Chu Kang','Little India','Macpherson','Mandai','Marine Parade','Mount Sophia','Mountbatten','Newton','Novena','Orchard','Outram','Pasir Panjang','Pasir Ris','Paya Lebar','Potong Pasir','Pulau Ubin','Punggol','Queenstown','Raffles Place','Redhill','River Valley','Robertson Quay','Seletar','Sembawang','Sengkang','Sentosa','SerangoonSerangoon Gardens','Siglap','Simei','Sixth Avenue','Somerset','Tampines','Tanglin','Tanglin Halt','Tanjong Pagar','Tanjong Rhu','Telok Blangah','Telok Kurau','Thomson','Tiong Bahru','Toa Payoh','Tuas','Ubi','Ulu Pandan','Upper Bukit Timah','Wessex Estate','West Coast','Woodlands','Yio Chu Kang','Yishun','one-north']

resultsDict = [] 
for location in neighborhoods:
	search_results = yelp_api.search_query(location=location, category_filter='food')
	totalResults = search_results['total']	
	for x in range (0, min(50, totalResults/20)):
		offsetValue = (str)(x*20)
		print "Query", x
		results = yelp_api.search_query(location=location, category_filter='food', offset=offsetValue)
		resultsDict.append(results)
# Answer to Challenge 9: Make an interactive version that prompts users for
# input.
#
# This is an interactive version of challenge_8.py

from yelpapi import YelpAPI
from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET

yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

# Example search by location text and term. Take a look at
# http://www.yelp.com/developers/documentation/v2/search_api for
# the various options available.

search_term = input("What do you want to search for: ")

response = yelp_api.search_query(term=search_term, location='seattle, wa', sort=2, limit=20)

counter = 0
for business in response['businesses']:
    if business['review_count'] >= 100:
        counter = counter + 1

print("of the 20 highest rated restaurants in seattle, {} have 100 or fewer reviews".format(counter))


Пример #56
0
def business_row(business):
    return [ business['location']['address'][0], 
     business['location']['city'],
     business['categories'][0][0],
     business['rating'],
     business['url'] ]

# Pulled the list from the neighborhoods shapefile at
# http://www.nyc.gov/html/dcp/html/bytes/applbyte.shtml#other
# Used http://dbfconv.com to convert the dbf (the data part of a shapefile) into a csv
neighborhoods = [ "Wakefield, Bronx", "Co-op City, Bronx", "Eastchester, Bronx", "Fieldston, Bronx", "Riverdale, Bronx", "Kingsbridge, Bronx", "Marble Hill, Manhattan", "Woodlawn, Bronx", "Norwood, Bronx", "Williamsbridge, Bronx", "Baychester, Bronx", "Pelham Parkway, Bronx", "City Island, Bronx", "Bedford Park, Bronx", "University Heights, Bronx", "Morris Heights, Bronx", "Fordham, Bronx", "East Tremont, Bronx", "West Farms, Bronx", "High  Bridge, Bronx", "Melrose, Bronx", "Mott Haven, Bronx", "Port Morris, Bronx", "Longwood, Bronx", "Hunts Point, Bronx", "Morrisania, Bronx", "Soundview, Bronx", "Clason Point, Bronx", "Throgs Neck, Bronx", "Country Club, Bronx", "Parkchester, Bronx", "Westchester Square, Bronx", "Van Nest, Bronx", "Morris Park, Bronx", "Belmont, Bronx", "Spuyten Duyvil, Bronx", "North Riverdale, Bronx", "Pelham Bay, Bronx", "Schuylerville, Bronx", "Edgewater Park, Bronx", "Castle Hill, Bronx", "Olinville, Bronx", "Pelham Gardens, Bronx", "Concourse, Bronx", "Unionport, Bronx", "Edenwald, Bronx", "Bay Ridge, Brooklyn", "Bensonhurst, Brooklyn", "Sunset Park, Brooklyn", "Greenpoint, Brooklyn", "Gravesend, Brooklyn", "Brighton Beach, Brooklyn", "Sheepshead Bay, Brooklyn", "Manhattan Terrace, Brooklyn", "Flatbush, Brooklyn", "Crown Heights, Brooklyn", "East Flatbush, Brooklyn", "Kensington, Brooklyn", "Windsor Terrace, Brooklyn", "Prospect Heights, Brooklyn", "Brownsville, Brooklyn", "Williamsburg, Brooklyn", "Bushwick, Brooklyn", "Bedford Stuyvesant, Brooklyn", "Brooklyn Heights, Brooklyn", "Cobble Hill, Brooklyn", "Carroll Gardens, Brooklyn", "Red Hook, Brooklyn", "Gowanus, Brooklyn", "Fort Greene, Brooklyn", "Park Slope, Brooklyn", "Cypress Hills, Brooklyn", "East New York, Brooklyn", "Starrett City, Brooklyn", "Canarsie, Brooklyn", "Flatlands, Brooklyn", "Mill Island, Brooklyn", "Manhattan Beach, Brooklyn", "Coney Island, Brooklyn", "Bath Beach, Brooklyn", "Borough Park, Brooklyn", "Dyker Heights, Brooklyn", "Gerritsen Beach, Brooklyn", "Marine Park, Brooklyn", "Clinton Hill, Brooklyn", "Sea Gate, Brooklyn", "Downtown, Brooklyn", "Boerum Hill, Brooklyn", "Prospect Lefferts Gardens, Brooklyn", "Ocean Hill, Brooklyn", "City Line, Brooklyn", "Bergen Beach, Brooklyn", "Midwood, Brooklyn", "Prospect Park South, Brooklyn", "Georgetown, Brooklyn", "Spring Creek, Brooklyn", "East Williamsburg, Brooklyn", "North Side, Brooklyn", "South Side, Brooklyn", "Navy Yard, Brooklyn", "Ocean Parkway, Brooklyn", "Fort Hamilton, Brooklyn", "Chinatown, Manhattan", "Washington Heights, Manhattan", "Inwood, Manhattan", "Hamilton Heights, Manhattan", "Manhattanville, Manhattan", "Central Harlem, Manhattan", "East Harlem, Manhattan", "Upper East Side, Manhattan", "Yorkville, Manhattan", "Lenox Hill, Manhattan", "Roosevelt Island, Manhattan", "Upper West Side, Manhattan", "Lincoln Square, Manhattan", "Clinton, Manhattan", "Midtown, Manhattan", "Murray Hill, Manhattan", "Chelsea, Manhattan", "Greenwich Village, Manhattan", "East Village, Manhattan", "Lower East Side, Manhattan", "Tribeca, Manhattan", "Little Italy, Manhattan", "Soho, Manhattan", "West Village, Manhattan", "Manhattan Valley, Manhattan", "Morningside Heights, Manhattan", "Gramercy, Manhattan", "Battery Park City, Manhattan", "Financial District, Manhattan", "Astoria, Queens", "Woodside, Queens", "Jackson Heights, Queens", "Elmhurst, Queens", "Howard Beach, Queens", "South Corona, Queens", "Forest Hills, Queens", "Kew Gardens, Queens", "Richmond Hill, Queens", "Downtown Flushing, Queens", "Long Island City, Queens", "Sunnyside, Queens", "East Elmhurst, Queens", "Maspeth, Queens", "Ridgewood, Queens", "Glendale, Queens", "Rego Park, Queens", "Woodhaven, Queens", "Ozone Park, Queens", "South Ozone Park, Queens", "College Point, Queens", "Whitestone, Queens", "Bayside, Queens", "Auburndale, Queens", "Little Neck, Queens", "Douglaston, Queens", "Glen Oaks, Queens", "Bellerose, Queens", "Kew Gardens Hills, Queens", "Fresh Meadows, Queens", "Briarwood, Queens", "Jamaica Center, Queens", "Oakland Gardens, Queens", "Queens Village, Queens", "Hollis, Queens", "South Jamaica, Queens", "St. Albans, Queens", "Rochdale, Queens", "Springfield Gardens, Queens", "Cambria Heights, Queens", "Rosedale, Queens", "Far Rockaway, Queens", "Broad Channel, Queens", "Breezy Point, Queens", "Steinway, Queens", "Beechhurst, Queens", "Bay Terrace, Queens", "Edgemere, Queens", "Arverne, Queens", "Seaside, Queens", "Neponsit, Queens", "Murray Hill, Queens", "Floral Park, Queens", "Holliswood, Queens", "Jamaica Estates, Queens", "Queensboro Hill, Queens", "Hillcrest, Queens", "Ravenswood, Queens", "Lindenwood, Queens", "Laurelton, Queens", "Lefrak City, Queens", "Belle Harbor, Queens", "Rockaway Park, Queens", "Somerville, Queens", "Brookville, Queens", "Bellaire, Queens", "North Corona, Queens", "Forest Hills Gardens, Queens", "St. George, Staten Island", "New Brighton, Staten Island", "Stapleton, Staten Island", "Rosebank, Staten Island", "West Brighton, Staten Island", "Grymes Hill, Staten Island", "Todt Hill, Staten Island", "South Beach, Staten Island", "Port Richmond, Staten Island", "Mariner's Harbor, Staten Island", "Port Ivory, Staten Island", "Castleton Corners, Staten Island", "New Springville, Staten Island", "Travis, Staten Island", "New Dorp, Staten Island", "Oakwood, Staten Island", "Great Kills, Staten Island", "Eltingville, Staten Island", "Annadale, Staten Island", "Woodrow, Staten Island", "Tottenville, Staten Island", "Tompkinsville, Staten Island", "Silver Lake, Staten Island", "Sunnyside, Staten Island", "Ditmas Park, Brooklyn", "Wingate, Brooklyn", "Rugby, Brooklyn", "Park Hill, Staten Island", "Westerleigh, Staten Island", "Graniteville, Staten Island", "Arlington, Staten Island", "Arrochar, Staten Island", "Grasmere, Staten Island", "Old Town, Staten Island", "Dongan Hills, Staten Island", "Midland Beach, Staten Island", "Grant City, Staten Island", "New Dorp Beach, Staten Island", "Bay Terrace, Staten Island", "Huguenot, Staten Island", "Pleasant Plains, Staten Island", "Butler Manor, Staten Island", "Charleston, Staten Island", "Rossville, Staten Island", "Arden Heights, Staten Island", "Greenridge, Staten Island", "Heartland Village, Staten Island", "Chelsea, Staten Island", "Bloomfield, Staten Island", "Bulls Head, Staten Island", "Carnegie Hill, Manhattan", "Noho, Manhattan", "Civic Center, Manhattan", "Midtown South, Manhattan", "Richmond Town, Staten Island", "Shore Acres, Staten Island", "Clifton, Staten Island", "Concord, Staten Island", "Emerson Hill, Staten Island", "Randall Manor, Staten Island", "Howland Hook, Staten Island", "Elm Park, Staten Island", "Remsen Village, Brooklyn", "New Lots, Brooklyn", "Paerdegat Basin, Brooklyn", "Mill Basin, Brooklyn", "Jamaica Hills, Queens", "Utopia, Queens", "Pomonok, Queens", "Astoria Heights, Queens", "Claremont Village, Bronx", "Concourse Village, Bronx", "Mount Eden, Bronx", "Mount Hope, Bronx", "Sutton Place, Manhattan", "Hunters Point, Queens", "Turtle Bay, Manhattan", "Tudor City, Manhattan", "Stuyvesant Town, Manhattan", "Flatiron, Manhattan", "Sunnyside Gardens, Queens", "Blissville, Queens", "Fulton Ferry, Brooklyn", "Vinegar Hill, Brooklyn", "Weeksville, Brooklyn", "Broadway Junction, Brooklyn", "Dumbo, Brooklyn", "Manor Heights, Staten Island", "Willowbrook, Staten Island", "Sandy Ground, Staten Island", "Egbertville, Staten Island", "Roxbury, Queens", "Homecrest, Brooklyn", "Middle Village, Queens", "Prince's Bay, Staten Island", "Lighthouse Hill, Staten Island", "Richmond Valley, Staten Island", "Malba, Queens", "Highland Park, Brooklyn", "Madison, Brooklyn" ]

# You'll have to put your own keys here -
# register at http://www.yelp.com/developers/
yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

with open('lunch-morningside-heights-yelp.csv', 'wb') as csvfile:
    business_writer = unicodecsv.writer(csvfile)
    business_writer.writerow(["Name", "Address", "City", "Category", "Rating", "URL"])

    for neighborhood in ["Morningside Heights"]:
        # Pause for a second so Yelp doesn't get unhappy with us
        time.sleep(1)

        print "Processing %s" % neighborhood
        response = yelp_api.search_query(term='lunch', location='%s, New York' % neighborhood, limit=20)

        for business in response['businesses']:
            # When we call business_row, maybe some are missing categories or addresses etc
            # If that happens, let's just ignore the error and keep on trucking
Пример #57
0
from yelpapi import YelpAPI
import argparse
from pprint import pprint
import json
from sets import Set

yelp_api = YelpAPI('HT2dPycSfSpTHWsyqt95wQ', 'uBi1MMxW4HbJn7sumEie9oLK3Jw', '2sgcGgH_Gs9UlKVQfY8uqte0lhjSpE8z', '2tItNfdQoaHzpqqh1WGJmaG85F0')

with open('location_all_latlngs.txt') as data_file:    
    location_latlngs = json.load(data_file)
with open('location_counts.txt') as data_file:    
    location_counts = json.load(data_file)

full_data = []
urls = Set()
business_keys = ["url", "rating", "review_count", "name", "location"]

for i in range(51, len(location_counts)): #0-50 already done.
#for i in range(4, 5):
    for index, ll in enumerate(location_latlngs.get(location_counts[i][0], [])):
        pass
        if index <= 20: #keep under 20
            try:
                response = yelp_api.search_query(term='scuba diving',  ll=ll)
                #full_data.append(response)
                for i in range(0, len(response['businesses'])):
                    if str(response['businesses'][i]['url']) not in urls:
                        business = response['businesses'][i]
                        business = { keep_key: response['businesses'][i][keep_key] for keep_key in business_keys }
                        # unwanted = set(business.keys()) - set(business_keys)
                        # for unwanted_key in unwanted: del business[unwanted_key] 
Пример #58
0
#!/usr/bin/env python
''' Simple script that access the yelp API and finds the 400 `best' restaurants within a bounding lat/long box.
    The queried responses are saved to a file for parsing.

    API keys stored in keys or just write yours in at the preemble
'''
from yelpapi import YelpAPI
import pickle
import keys

consumer_key = keys.consumer_key
consumer_secret = keys.consumer_secret
token = keys.token
token_secret = keys.token_secret

yelp_api = YelpAPI(consumer_key, consumer_secret, token, token_secret)

"""
    Example search by location text and term. Take a look at http://www.yelp.com/developers/documentation/v2/search_api for
    the various options available.
"""
# response = yelp_api.search_query(term='restaurants', location='idaho falls, ID', sort=1, offset=20)
# print('region center (lat,long): %f,%f\n' % (response['region']['center']['latitude'], response['region']['center']['longitude']))
# for business in response['businesses']:
#     print('%s\n\tYelp ID: %s\n\trating: %g (%d reviews)\n\taddress: %s' % (business['name'], business['id'], business['rating'],
#                                                                            business['review_count'], ', '.join(business['location']['display_address'])))
#
#

response = []
Пример #59
0
# Scrapes a whole city from Yelp.

import argparse, csv, collections, ConfigParser, time, json
from yelpapi import YelpAPI

parser = argparse.ArgumentParser()
parser.add_argument('--neighborhoods_file', default='data/sffind_neighborhoods.json')
parser.add_argument('--config_file', default='config.txt')
parser.add_argument('--output_file', default='yelp_results.json')
parser.add_argument('--limit', help='stop after N businesses, for testing', type=int)
args = parser.parse_args()

config = ConfigParser.ConfigParser()
config.read('config.txt')
yelp_api = YelpAPI(config.get('yelp', 'consumer_key'),
        config.get('yelp', 'consumer_secret'), config.get('yelp', 'token'),
        config.get('yelp', 'token_secret'))

# https://www.yelp.com/developers/documentation/v2/search_api
all_businesses = []
num_results_so_far = 0
# bounds=sw_latitude,sw_longitude|ne_latitude,ne_longitude
# bounds = '37.70,-122.5|37.76,-122.35' # lower half of SF
# bounds = '37.76,-122.5|37.82,-122.35' # upper half of SF
bounds = '37.70,-122.55|37.82,-122.35' # all SF, rough handmade query.
while True:
    try:
        # results = yelp_api.search_query(category_filter='coffee',
        #     location='San Francisco, CA', offset=num_results_so_far)
        results = yelp_api.search_query(category_filter='coffee',
            bounds=bounds, offset=num_results_so_far)
Пример #60
0
from yelpapi import YelpAPI
from yelp_authentication import CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET

yelp_api = YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET)

# Example search by location text and term. Take a look at
# http://www.yelp.com/developers/documentation/v2/search_api for
# the various options available.

print('***** 5 best rated ice cream places in Austin, TX *****')

response = yelp_api.search_query(term='ice cream', location='austin, tx', sort=2, limit=5)

print('region center (lat,long): {},{}\n'.format(response['region']['center']['latitude'], response['region']['center']['longitude']))

for business in response['businesses']:
    print('{}\n\tYelp ID: {}\n\trating: {} ({} reviews)\n\taddress: {}'.format(business['name'], business['id'], business['rating'], business['review_count'], business['location']['display_address']))