当前位置: 首页>>代码示例>>Python>>正文


Python YelpAPI.search_query方法代码示例

本文整理汇总了Python中yelpapi.YelpAPI.search_query方法的典型用法代码示例。如果您正苦于以下问题:Python YelpAPI.search_query方法的具体用法?Python YelpAPI.search_query怎么用?Python YelpAPI.search_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yelpapi.YelpAPI的用法示例。


在下文中一共展示了YelpAPI.search_query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Yelp

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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'])
开发者ID:ab-geek,项目名称:DjangoWebScraper,代码行数:28,代码来源:yelp.py

示例2: nearby_yelp

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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
开发者ID:mrbhandari,项目名称:eazyhouz,代码行数:27,代码来源:social_data.py

示例3: get_info_from_api

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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
开发者ID:SandeepReddyVanga,项目名称:TravelWorldSpunky,代码行数:30,代码来源:yelp.py

示例4: main

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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='')
开发者ID:amalhot5,项目名称:TravelApp,代码行数:34,代码来源:api-test.py

示例5: min_query

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
    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        
开发者ID:CooperativeOrganizationOfPeople,项目名称:Brunch,代码行数:31,代码来源:yelp_api.py

示例6: filter_by_category

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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
开发者ID:cristinamclarkin,项目名称:reservationtonight,代码行数:34,代码来源:yelp_api.py

示例7: food

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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!")
开发者ID:Jarada,项目名称:jenni,代码行数:27,代码来源:food.py

示例8: Yelp

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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)
开发者ID:newtonjain,项目名称:hacktheplanet,代码行数:14,代码来源:yelp.py

示例9: full_query

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
    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
开发者ID:CooperativeOrganizationOfPeople,项目名称:Brunch,代码行数:14,代码来源:yelp_api.py

示例10: callYelp

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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
开发者ID:bxiao0801,项目名称:backup,代码行数:21,代码来源:apiCall.py

示例11: YelpGain

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
    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
开发者ID:toming90,项目名称:2014Spring-CSCE670-Final-Project-Cupid,代码行数:26,代码来源:UI.py

示例12: YelpAPI

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
# 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']))

开发者ID:makoshark,项目名称:yelp-api-cdsw-solutions,代码行数:17,代码来源:challenge_6.py

示例13: YelpAPI

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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)
开发者ID:spinningarrow,项目名称:yelpy,代码行数:9,代码来源:yelpSearch.py

示例14: YelpAPI

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
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))
开发者ID:kmhawkes,项目名称:python-gis,代码行数:33,代码来源:test.py

示例15: xrange

# 需要导入模块: from yelpapi import YelpAPI [as 别名]
# 或者: from yelpapi.YelpAPI import search_query [as 别名]
#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'])
开发者ID:diegollarrull,项目名称:EDAV_project_3,代码行数:33,代码来源:yelp_api.py


注:本文中的yelpapi.YelpAPI.search_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。