Ejemplo n.º 1
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
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
Archivo: food.py Proyecto: Jarada/jenni
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!")
Ejemplo n.º 5
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
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'])
Ejemplo n.º 11
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='')
Ejemplo n.º 12
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!")
Ejemplo n.º 13
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'])
    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        
Ejemplo n.º 15
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
Ejemplo n.º 16
0
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
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)
Ejemplo n.º 20
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)
Ejemplo n.º 21
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"]
Ejemplo n.º 22
0
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 ""
Ejemplo n.º 23
0
class YelpClient():
    def __init__(self):
        self.yelp = YelpAPI(API_KEY)

    def get_tag_set(self):
        return random.sample(prefs, pref_size)

    def get_random_location(self):
        lat = DC["lat"] + random.uniform(-loc_dev * 2, loc_dev * 2)
        long = DC["long"] + random.uniform(-loc_dev * 2, loc_dev * 2)

        return (lat, long)

    def get_venues(self, lat, long, categories):
        venues = self.yelp.search_query(location='DC',
                                        latitude=lat,
                                        longitude=long,
                                        categories=categories,
                                        limit=50,
                                        open_now=True)
        return venues

    def generate_venue_set(self):
        lat, long = self.get_random_location()
        tags = self.get_tag_set()
        categories = ','.join(tags)
        # print(categories)
        venue_set = self.get_venues(lat, long, categories)["businesses"]
        # print(venue_set)

        venues = []
        for v in venue_set:
            categories = [c['alias'] for c in v["categories"]]

            address = str(v["location"]["address1"]) + " " + str(v["location"]["city"]) + ", " + \
                str(v["location"]["state"]) + " " + \
                str(v["location"]["zip_code"])

            venue = {
                "yelp_id":
                v["id"],
                "name":
                v["name"],
                "coordinates":
                [v["coordinates"]["latitude"], v["coordinates"]["longitude"]],
                "address":
                address,
                "categories":
                categories,
                "image":
                v["image_url"]
            }
            venues.append(venue)

        return venues
Ejemplo n.º 24
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)
    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
Ejemplo n.º 26
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)
Ejemplo n.º 27
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
Ejemplo n.º 28
0
def startPage():
    yelp_api = YelpAPI(api_key)
    #ipAddress = "23.121.182.143"    #for testing locally #using duke IP bc duke gardens bug
    ipAddress = getIP()           #for deployment
    locCoor = getLoc(ipAddress)
    yelpJson = yelp_api.search_query(latitude = locCoor['lat'], longitude = locCoor['lon'], limit = NUM_REST)
    initObjs(yelpJson, 5)
    if request.method == 'POST':  #this block is only entered when the form is submitted
        #read in form values
        form.query = request.form.get('query')
        form.location = request.form.get('location')
        form.distance = request.form.get('distance')
        form.price = str(int(request.form.get('price')))
        #search with form values
        yelpJson = yelp_api.search_query(term = form.query, location = form.location, distance = form.distance, price = form.price, limit = NUM_REST)
        if checkResults(yelpJson)==-1: #if the search is too specific
            return '<h1> Your search did not return enough restaurants to display, please try again</h1><a href = "/" class = "w3-xlarge w3-button ">Clear Search</a>'
        initObjs(yelpJson, 5)
        #render page after search using values from form
        return render_template('finalPage.html',
                                ipA = ipAddress,
                                term = form.query,
                                mapR = form.distance,
                                latitude = yelpJson['region']['center']['latitude'],
                                longitude = yelpJson['region']['center']['longitude'],
                                r0=resObjs[0],
                                r1=resObjs[1],
                                r2=resObjs[2],
                                r3 = resObjs[3],
                                r4=resObjs[4])
    #render page before search with defaults and ip location
    return render_template('firstPage.html',
                            ipA = ipAddress,
                            latitude = locCoor['lat'],
                            longitude = locCoor['lon'],
                            r0=resObjs[0],
                            r1=resObjs[1],
                            r2=resObjs[2],
                            r3 = resObjs[3],
                            r4=resObjs[4])
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
    def list(self, request):

        yelp_api = YelpAPI(api_key)
        search_location = self.request.query_params.get("location", None)
        search_total = yelp_api.search_query(location=search_location,
                                             categories='parking, All',
                                             sort_by='rating',
                                             limit=0)

        if search_total["total"] <= 50:
            offset_amt = 0
        elif 50 < search_total["total"] <= 1000:
            offset_amt = (search_total["total"] - 50)
        else:
            offset_amt = 950

        search_results = yelp_api.search_query(location=search_location,
                                               categories='parking, All',
                                               sort_by='rating',
                                               limit=50,
                                               offset=offset_amt)

        return Response(search_results["businesses"])
Ejemplo n.º 31
0
def search_yelp():

    client_id = yelp_crediatials.client_id
    api_key = yelp_crediatials.api_key

    yelp_api = YelpAPI(api_key)
    term = 'Mexican restaurant bar'
    location = 'Boston, MA'
    search_limit = 50
    response = yelp_api.search_query(term=term,
                                     location=location,
                                     limit=search_limit)
    print(response)
    '''
def scrape_healthy_restaurants():
    city_list = []
    for tup in top_cities_data():
        city_list.append(tup[0])

    yelp_api = YelpAPI(API_KEY)
    healthy_restuarants_dict = {}

    #get restaurants with key word "healthy in each city
    for city in city_list:
        search_results = yelp_api.search_query(term = 'healthy', location = city)
        healthy_restuarants_dict[city] = search_results["total"]
    
    return(healthy_restuarants_dict)
Ejemplo n.º 33
0
    def get(self, request, *args, **kwargs):
        yelp_api = YelpAPI(settings.YELP_API_KEY)

        search_results = yelp_api.search_query(**self.request.GET)

        term = request.GET.get('term')
        longitude = float(request.GET.get('longitude'))
        latitude = float(request.GET.get('latitude'))
        results_count = search_results['total']
        map_models.Search.objects.create(term=term,
                                         position=Point(longitude, latitude),
                                         results_count=results_count)

        return JsonResponse(search_results)
Ejemplo n.º 34
0
async def async_deep_query(terms,
                           location,
                           offset=0,
                           limit=20,
                           radius=40000,
                           output='yelper.csv',
                           pages=-1):
    """Define the application entrypoint."""
    # Prepare the Yelp client.
    yelp_api = YelpAPI(os.environ['YELP_API_KEY'])
    params = {
        'term': terms,
        'location': location,
        'offset': offset,
        'limit': limit,
        'radius': radius,
    }

    # Prepare the CSV file.
    fieldnames = dataclasses.asdict(YelpBusiness('fake')).keys()
    with open(output, 'w') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()

        # Search Yelp.
        while True:
            search_results = yelp_api.search_query(**params)

            # Check whether we need to process further or not.
            if not search_results:
                break
            if not search_results['businesses']:
                break
            if (params['offset'] / params['limit']) >= pages > 0:
                break

            # Process the results.
            tasks = [
                deep_entry_parsing(business, params['offset'] + i)
                for i, business in enumerate(search_results['businesses'])
            ]
            page_results = await asyncio.gather(*tasks)

            # Write the entries to the file and flush.
            for entry in page_results:
                writer.writerow(dataclasses.asdict(entry))
            csvfile.flush()

            # Update the offset before looping again.
            params['offset'] += params['limit']
Ejemplo n.º 35
0
def random_zips(list_of_zips, n_zips, key):
    # Initializing the Yelp API using key provided
    yelp = YelpAPI(key)

    # Casting the data type of the DataFrame into strings
    list_of_zips = [str(i) for i in list_of_zips]

    # Creating a Series from the inputted list of zip codes
    zip_list = pd.Series(list_of_zips)

    # Creating an empty list of the number of businesses in a zip code
    zip_bus_list = []

    for zipcode in zip_list:
        # Using exceptions in case Yelp APIs limitations are met
        try:
            # Using the Yelp API search query to retrieve 1 business per zip code
            search = yelp.search_query(location=zipcode, limit=1)

            # Appending to the list search['total'], which is the total number
            # of businesses in a zip code (this metadata is available with each inidividual
            # business search call)
            zip_bus_list.append(search['total'])
        except:
            pass

    # Converting the list of businesses into a Series, and then into a DataFrame
    # that includes the zip code and number of businesses
    zip_bus_list_series = pd.Series(zip_bus_list)
    df_business = pd.concat([zip_list, zip_bus_list_series], axis=1)

    # Renaming the appended columns to 'zipcode' and 'n_business'
    df_business = df_business.rename(columns={0: 'zipcode', 1: 'n_business'})

    # Only choosing zip codes that have between 50 and 1000 businesses
    df_avail = df_business[(df_business['n_business'] < 1000)
                           & (df_business['n_business'] > 50)]

    # Setting a random seed for reproducibility
    np.random.seed(42)

    # Choosing n_zips specified amount of
    # random zipcodes from the available list
    if (n_zips > df_avail.shape[0]):
        print('You specified more zipcodes than are available in your list')
        n_zips = df_avail.shape[0]

    zip_list = np.random.choice(df_avail['zipcode'], n_zips, replace=False)
    return zip_list.tolist()
Ejemplo n.º 36
0
def main():

    try:
        yelp_api = YelpAPI(myapi.api_key(), timeout_s=3.0)
        search_results = yelp_api.search_query(location='77042', radius='8000')

    except:
        print("error: ", sys.exc_info()[0])

    blist = json.loads(json.dumps(search_results))

    for business in blist["businesses"]:
        print(business["name"].encode('ascii', 'ignore'))
        print(business["url"].encode('ascii', 'ignore'))
        print(business["phone"].encode('ascii', 'ignore'))
Ejemplo n.º 37
0
def get_results(term, location):
    yelp_api = YelpAPI(os.environ["YELP_API_KEY"])

    results = yelp_api.search_query(term=term,
                                    location=location,
                                    limit=50,
                                    sort_by="review_count",
                                    radius=8000)

    businesses = results["businesses"]
    distance_business = []
    for business in businesses:
        if business["distance"] < 8000:
            distance_business.append(business)
    return distance_business
Ejemplo n.º 38
0
    def search_yelp(self, youcook_search_query):
        yelp_api = YelpAPI(self.api_key)
        term = youcook_search_query
        location = 'Boston'
        search_limit = 5
        response = yelp_api.search_query(term=term,
                                         location=location,
                                         limit=search_limit,
                                         sort_by="rating",
                                         open_now=True,
                                         price="1")
        # randomly select of the restaurants for diversity
        random_int = random.randint(0, search_limit - 1)
        rand_response = response["businesses"][random_int]

        return rand_response["url"]  # return url of the restaurant
Ejemplo n.º 39
0
def getYelpData():
    count = 0
    # File containing restaurant names: RestaurantNames.txt
    input_file = open("RestaurantNames.txt", "r")
    out_file = open("yelp_data_final.txt", "w")
    data = input_file.read()
    json_data = json.loads(data)
    yelp_api = YelpAPI(
        't3EnvPrJD5QFX9byrhYDronkMOjI17LzpSvePzEIRd-NS1FzIK_ayRigJn_iH8qLFI40RRmOXw56V38qcB-JBYdKImFYCg4F8eSmiAQEaOTLfkcNOAz3zxTuWQjBXHYx'
    )
    restaurant_data_yelp = []
    for each_data in json_data:
        each_data = json_data[each_data]
        res_data = each_data
        search_results = yelp_api.search_query(term=each_data["name"],
                                               location='Chicago, IL')
        #search_results=json.loads(input_file2.read())
        #json.dump(search_results,out_file)
        search_results['businesses'][1]
        for each_result in search_results['businesses']:
            score1 = fuzz.partial_ratio(
                each_result['location']['display_address'],
                each_data["street_address"])
            score2 = fuzz.partial_ratio(each_result['name'], each_data["name"])
            if score1 > 90 and score2 > 90:
                if 'id' in each_result:
                    res_data['yelp_id'] = each_result['id']
                if 'rating' in each_result:
                    res_data['rating'] = each_result['rating']
                if 'review_count' in each_result:
                    res_data['review_count'] = each_result['review_count']
                if 'url' in each_result:
                    res_data['url'] = each_result['url']
                if 'categories' in each_result:
                    res_data['category'] = each_result['categories']
                if 'display_phone' in each_result:
                    res_data['phone_number'] = each_result['display_phone']
                res_data['lat'] = each_result['coordinates']['latitude']
                res_data['lon'] = each_result['coordinates']['longitude']
                restaurant_data_yelp.append(res_data)
                print("processed:", count)
                count = count + 1
    json.dump(restaurant_data_yelp,
              out_file,
              sort_keys=True,
              indent=4,
              separators=(',', ': '))
Ejemplo n.º 40
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
    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
Ejemplo n.º 42
0
# argparser.add_argument('token_secret', type=str, help='Yelp v2.0 API token secret')
# args = argparser.parse_args()

consumer_key = 'cdKLIdRVUr7vnYnsTWbiIA'
consumer_secret = 'gujwKmCVeIRDxB1QiWHCK4FPKiQ'
token = 'npddkfvdPPcQP9JtroXIeo6GaWqPIlWR'
token_secret = 'R9TFAp59AbjY8qtBVs0lwlwww3w'

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 *****\n%s\n' % "yelp_api.search_query(term='ice cream', location='austin, tx', sort=2, limit=5)")
response = yelp_api.search_query(term='ice cream', location='austin, tx', sort=2, limit=5)
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'])))

print('\n-------------------------------------------------------------------------\n')

"""
    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 *****\n%s\n' % "yelp_api.search_query(category_filter='bikerentals', bounds='37.678799,-123.125740|37.832371,-122.356979', limit=5)")
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('%s\n\tYelp ID: %s\n\trating: %g (%d reviews)\n\taddress: %s' % (business['name'], business['id'], business['rating'],
Ejemplo n.º 43
0
                                                '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')


"""
    Example search by centroid and category.
    
    all Yelp categories: https://www.yelp.com/developers/documentation/v3/all_category_list
    centroid: https://www.flickr.com/places/info/2487956
"""
print('***** 5 bike rentals in San Francisco *****\n{}\n'.format("yelp_api.search_query(categories='bikerentals', "
                                                                 "longitude=-122.4392, latitude=37.7474, limit=5)"))
response = yelp_api.search_query(categories='bikerentals', longitude=-122.4392, latitude=37.7474, limit=5)
pprint(response)
print('\n-------------------------------------------------------------------------\n')
# 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']))

# 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']))

# 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))


Ejemplo n.º 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 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']))
Ejemplo n.º 48
0
from yelpapi import YelpAPI
import json

yelp_api = YelpAPI('a5oBT4RnnHpt6rtHQWsGYg', '61UpHpxNDVJfpACumIIJNIR2nJ8', '-PlfjeTyjnMSGP67pQbopdxJ-lXE70Bn', 'ewGlo-jkCt0LpNYphzr2SxaEtCY')
search_results = yelp_api.search_query(location='singapore')

print json.dumps(search_results)
Ejemplo n.º 49
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']))

Ejemplo n.º 50
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()
Ejemplo n.º 51
0
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] 
                        full_data.append(business)
                    urls.add(str(response['businesses'][i]['url']))
            except:
                pass
        
with open('yelp_full_data.txt', 'w') as outfile:
    json.dump(full_data, outfile)
with open('yelp_urls.txt', 'w') as outfile:
Ejemplo n.º 52
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)
Ejemplo n.º 53
0
     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
            try:
                business_writer.writerow(business_row(business))
            except:
                print "Failed!"
                pass
Ejemplo n.º 54
0
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
		#count = d.setdefault()
Ejemplo n.º 55
0
#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)]
lon_intervals = [float(i) / 10 for i in xrange(7)]



for lat in lat_intervals:
     for lon in lon_intervals:
         bounds = str(BaseLat + lat) + ',' + str(BaseLon + lon) + '|' + str(BaseLat + lat + 0.1) + ',' + str(BaseLon + lon + 0.1)
         print bounds
         response = yelp_api.search_query(term='alcohol',  bounds=bounds, sort=2, limit=20, offset=0)
         response2 = yelp_api.search_query(term='alcohol', bounds=bounds, sort=2, limit=20, offset=20)
         if response['businesses'] != []:
            response_code = yelp_results_collection.insert(response['businesses'])
         if response2['businesses'] != []:
            response_code2 = yelp_results_collection.insert(response2['businesses'])
         time.sleep(10)

Lats2 = yelp_results_collection.aggregate([{'$project': {'name' : '$id',
                                                         'longitude': '$location.coordinate.longitude',
                                                         'latitude': '$location.coordinate.latitude',
                                                         'rating' : '$rating'}}])

f = open('./yelp_rating.csv', 'w')
csv_file = csv.writer(f)
writer = csv.DictWriter(f, fieldnames = ['_id','name','latitude','longitude','rating'])
Ejemplo n.º 56
0
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 = []

for offset in range(0,400,20):
    tmp = yelp_api.search_query(term='restaurants', bounds='43.446888,-112.097128|43.542030,-111.931131', sort=0, offset=offset,radius_filter=8000)
    response.append(tmp)
    print(tmp)

pickle.dump(response, open('restaurants.p','wb'))
Ejemplo n.º 57
0
#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)):
            offsetValue = (str)(x*20)
            #print("Query", x)

            results = yelp_api.search_query(location=location, category_filter='active', offset=offsetValue, cc='SG')
            row=0
            for r in results:
                results['businesses'][row]['identifier'] = results['businesses'][row]['id']
                del results['businesses'][row]['id']
Ejemplo n.º 58
0
sort_mode       = 2

# initialize an api object
yelp_api = YelpAPI(consumer_key, consumer_secret, token, token_secret)

# write output to file
with open(output_file, 'w+b') as fh:
    writer = csv.writer(fh)

    # look here for the terms you can use for searching and their meaning
    # http://www.yelp.com/developers/documentation/v2/search_api#searchMSL
    for offset in search_offsets:
        print "At offset: %d" % offset
        search_results = yelp_api.search_query(
                             location = search_location,
                             term     = search_term,
                             offset   = offset,
                             sort     = sort_mode
                         )


        for biz in search_results.get('businesses'):

            name      = biz.get('name')
            rating    = biz.get('rating')
            # address is always returned as a list; get first element
            address   = biz.get('location').get('address')[0]
            zip_code  = biz.get('location').get('postal_code')

            # geocode addresses
            geo_results = Geocoder.geocode('%s, %s' % (address, zip_code))
Ejemplo n.º 59
0
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)
    except Exception as e:
        print "Error sending request, writing file and quitting."
        print e
        break

    print "This many so far: %d, this many total: %d" % (num_results_so_far, results['total'])
    for business in results['businesses']:
        if business['is_closed']:
            print "Not including, permanently closed: %s" % business['name']
            continue
        try:
            all_businesses.append({'name': business['name'],
                'latitude': business['location']['coordinate']['latitude'],
                'longitude': business['location']['coordinate']['longitude'],
            })
Ejemplo n.º 60
0
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']

    num_results_so_far += len(results['businesses'])
    if num_results_so_far >= results['total']:
        break
    time.sleep(3)
# results = yelp_api.search_query(category_filter='coffee',
#         location='Noe Valley, San Francisco, CA', offset = 20)
#