本文整理汇总了Python中yelp.client.Client.search方法的典型用法代码示例。如果您正苦于以下问题:Python Client.search方法的具体用法?Python Client.search怎么用?Python Client.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yelp.client.Client
的用法示例。
在下文中一共展示了Client.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Yelp
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def Yelp(command, yelp_authkeys):
lowerCom = command.lower()
searchType = re.findall(r'yelp (.*?) in', lowerCom, re.DOTALL)
searchKey=""
for t in searchType:
searchKey+=t
searchType=searchKey
params = {
'term' : searchType
}
keyword = 'in '
before_key, keyword, after_key = lowerCom.partition(keyword)
location = after_key
auth = Oauth1Authenticator(
consumer_key = yelp_authkeys["CONSUMER_KEY"],
consumer_secret= yelp_authkeys["CONSUMER_SECRET"],
token = yelp_authkeys["TOKEN"],
token_secret = yelp_authkeys["TOKEN_SECRET"]
)
client = Client(auth)
response = client.search(location, **params)
out =""
for x in range(0,3):
out += str(x+1) + ". " + str(response.businesses[x].name) + "\n Address: " + str(response.businesses[x].location.display_address).strip('[]').replace("'","").replace(",","") + "\n Ratings: " + str(response.businesses[x].rating) + " with " + str(response.businesses[x].review_count) + " Reviews \n Phone: " + str(response.businesses[x].display_phone) + "\n"
return(out)
示例2: yelp
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def yelp(loc, c, paramsA, paramsB):
print "YELP"
auth = Oauth1Authenticator(
consumer_key="Q7OyV59ytZdO-zuAo3Rl0g",
consumer_secret="xNOuCM0FhUthxpA8RFiQgEPtFaM",
token="EE_wX2qYssWNzSLL65gFCg9ciTbf1sEL",
token_secret="gHEEbPgA66UVFAC3bmmehi6kY3I"
)
client = Client(auth)
print "YELPC"
print c
if(c == 1 or c == '1'):
print 1111111111111111111111111111111111111111
# params1 = {
# 'sort': '2',
# #'sort': '1',
# 'term': 'food',
# 'lang': 'en',
# #'radius_filter': '10'
# }
# print "YELP1"
response = client.search(loc, **paramsA)
elif(c == 2 or c == '2'):
print 222222222222222222222222222222222222222
# params2 = {
# 'sort': '2',
# #'sort': '1',
# 'term': 'fun',
# 'lang': 'en',
# #'radius_filter': '10'
# }
response = client.search(loc, **paramsB)
#print mainlist
print "YELPM"
for i in range(10):
mainlist.append(response.businesses[i].name)
ratinglist.append(response.businesses[i].rating)
citylist.append(response.businesses[i].location.city)
print mainlist
示例3: api_callee
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def api_callee(event, context):
# read API keys
with io.open('config_secret.json') as cred:
creds = json.load(cred)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
params = {
'term': event['item'],
'lang': 'en',
'limit': 5
}
#print event['item']
#print event['location']
response = client.search(event['location'], **params)
#print response
placesYelp = ""
#print response.businesses[0]
if response.businesses == None:
placesYelp = 'jankiap50_error_yelp'
elif len(response.businesses) == 0:
placesYelp = 'jankiap50'
else:
placesYelp = str(response.businesses[0].name) +'@'+ \
str(response.businesses[0].mobile_url.partition("?")[0]) +'@' + \
str(response.businesses[0].image_url) +'@' + \
str(response.businesses[0].rating) +'@' + \
str(response.businesses[0].display_phone)+'@' + \
str(response.businesses[1].name)+'@' + \
str(response.businesses[1].mobile_url.partition("?")[0])+'@' + \
str(response.businesses[1].image_url) +'@' + \
str(response.businesses[1].rating)+'@' + \
str(response.businesses[1].display_phone)+'@' + \
str(response.businesses[2].name)+'@' + \
str(response.businesses[2].mobile_url.partition("?")[0])+'@'+ \
str(response.businesses[2].image_url) +'@' + \
str(response.businesses[2].rating)+'@' + \
str(response.businesses[2].display_phone)+'@' + \
str(response.businesses[3].name)+'@' + \
str(response.businesses[3].mobile_url.partition("?")[0])+'@' + \
str(response.businesses[3].image_url) +'@' + \
str(response.businesses[3].rating)+'@' + \
str(response.businesses[3].display_phone)+'@' + \
str(response.businesses[4].name)+'@' + \
str(response.businesses[4].mobile_url.partition("?")[0])+'@'+ \
str(response.businesses[4].image_url) +'@' + \
str(response.businesses[4].rating)+'@' + \
str(response.businesses[4].display_phone)+'@'
#return response.businesses[0].name, response.businesses[0].url.partition("?")[0], response.businesses[0].rating, response.businesses[0].display_phone
#print str(placesYelp)
result=placesYelp.encode('ascii', 'ignore')
return result
示例4: fetchCoffeeBusinesses
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def fetchCoffeeBusinesses(self):
with io.open(self.yelp_auth_path) as auth_file:
creds = json.load(auth_file)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
params = {
'term': 'coffee',
'lang': 'en'
}
coffee_shops = client.search('San Francisco', **params)
return coffee_shops.businesses
示例5: yelpsearchapi_by_location
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def yelpsearchapi_by_location(loc):
DEFAULT_LOCATION = loc
CREDENTIALS_PATH = 'static/credentials.json'
RADIUS_FILTER_METERS = 1000
NEAREST_SORT_OPTION = 1
LIMIT = 5
# read api keys credentials
with io.open(CREDENTIALS_PATH) as cred:
creds = json.load(cred)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
# enter parameters
params = { 'category_filter': 'bars',
'radius_filter': RADIUS_FILTER_METERS,
'sort': NEAREST_SORT_OPTION,
'limit': LIMIT }
if loc:
response = client.search(loc, **params)
else:
response = client.search(DEFAULT_LOCATION, **params)
return response
示例6: search_yelp
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def search_yelp(nouns):
auth = Oauth1Authenticator(
consumer_key=environ.get('YELP_CONSUMER_KEY'),
consumer_secret=environ.get('YELP_CONSUMER_SECRET'),
token=environ.get('YELP_TOKEN'),
token_secret=environ.get('YELP_TOKEN_SECRET')
)
terms = reduce(lambda prev, curr: prev + ' ' + curr, nouns, ''),
print terms
client = Client(auth)
return client.search('New York, NY', **{
'term': nouns[0],
'limit': 3,
'category_filter': 'restaurants'
});
示例7: get
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def get(location, term):
print('in yelp_api.get, with term: ', term)
params = {
'location': location,
'term': term,
}
auth = Oauth1Authenticator(**settings.YELP_CONFIG)
client = Client(auth)
response = client.search(**params)
total_results = response.total
businesses = [business for business in response.businesses]
average_rating = sum([business.rating for business in businesses])/len(businesses)
return {
'total': total_results,
'selected_businesses_count': len(businesses),
'average_rating': average_rating,
}
示例8: YelpService
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
class YelpService(object):
def __init__(self):
auth = Oauth1Authenticator(
consumer_key="uz2Sv5gO6dwlnjRv3BqzwA",
consumer_secret="VhgG3IucBO_eTheOlWzrVuuVjbU",
token="bN1HD9FSDGqUWjzxbIkho_N1muVe0xcA",
token_secret="hEdALK5D2gCI9-H3GwGKAw1jEYo"
)
self.client = Client(auth)
self._business_cache = {}
def get_location(self, yelp_id):
"""
Get the location of a yelp business
"""
business = self._get_business(yelp_id)
return business.location.coordinate
def get_name(self, yelp_id):
"""
Get the name of a location
"""
business = self._get_business(yelp_id)
return business.name
def get_url(self, yelp_id):
"""
Get the url to the yelp side of a business
"""
business = self._get_business(yelp_id)
return business.url
def _get_business(self, yelp_id):
if yelp_id in self._business_cache:
return self._business_cache[yelp_id]
else:
response = self.client.get_business(yelp_id)
self._business_cache[yelp_id] = response.business
return response.business
def search(self, query, location):
response = self.client.search(location=location, term=query)
return response.businesses
示例9: get_businesses_from_yelp
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def get_businesses_from_yelp(location_string):
""" Search Yelp through API for knitting/yarn, save results to objects
location_string: the user location string
:return: list of YelpBusiness objects for input city
"""
# read API keys
with io.open('yelp_config_secret.json') as cred:
creds = json.load(cred)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
yelp_knitting_category_alias = 'knittingsupplies'
params = {
'category_filter': yelp_knitting_category_alias
}
yelp_results = client.search(location_string, **params)
list_of_biz = []
for business in yelp_results.businesses:
biz_name = business.name
biz_addr = business.location.display_address
biz_city = business.location.city
biz_lat = business.location.coordinate.latitude
biz_long = business.location.coordinate.longitude
biz_url = business.url
biz_closed = business.is_closed
# exclude businesses that are closed
if biz_closed == False:
new_biz = YelpBusiness(biz_name=biz_name,
biz_addr=biz_addr[0],
biz_city=biz_city,
biz_lat=biz_lat,
biz_long=biz_long,
biz_url=biz_url)
list_of_biz.append(new_biz)
return list_of_biz
示例10: yelp
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def yelp(self, words):
print("yelp")
auth = Oauth1Authenticator(
consumer_key=cf.get("yelp", "ConsumerKey"),
consumer_secret=cf.get("yelp", "ConsumerSecret"),
token=cf.get("yelp", "Token"),
token_secret=cf.get("yelp", "TokenSecret"),
)
client = Client(auth)
if "around me" or "near me" in words:
print("yelp")
params = {"term": "food"}
response = client.search("Lawrence", **params)
text = (
"Some of the restaurants are "
+ response.businesses[0].name
+ " and "
+ response.businesses[1].name
)
print(text)
return text
示例11: yelp_search_resturants_general
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def yelp_search_resturants_general(self, city, state, radius):
cityState = city + ',' + state
auth = Oauth1Authenticator(
consumer_key= 'bM0VPHWh91R0g46amxYbnA',
consumer_secret='l-p2JF_V2BZSsNWGPRT7QywfoGE',
token='rD8K96AXRAxiwI_R_mQwwdMUwb65Ctt_',
token_secret= 'ugp2wQ8Pb4tcV0Qc8pc23MlkvLw'
)
client = Client(auth)
print "My client is authenticated" + str(client)
params = {
'term': 'restaurants',
'radius_filter': str(int(radius) * 1609),
'sort': '0',
'limit':'20'
}
data = client.search(cityState, **params)
return data
示例12: yelp_search_attractions
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def yelp_search_attractions(self, city, state, radius):
cityState = city + ',' + state
#Authentication keys for yelp
auth = Oauth1Authenticator(
consumer_key= 'bM0VPHWh91R0g46amxYbnA',
consumer_secret='l-p2JF_V2BZSsNWGPRT7QywfoGE',
token='rD8K96AXRAxiwI_R_mQwwdMUwb65Ctt_',
token_secret= 'ugp2wQ8Pb4tcV0Qc8pc23MlkvLw'
)
client = Client(auth)
params = {
'category_filter': 'landmarks,museums,beaches',
'radius_filter': str(int(radius) * 1609),
'sort': '0',
'limit': '20'
}
data = client.search(cityState, **params)
return data
示例13: get_restaurants
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def get_restaurants(city, offset):
"""
Returns API response from Yelp API call to get restaurants for a city, with the results offset.
Note that Yelp only returns 20 results each time, which is why we need to offset if we want
the next Nth results.
"""
# Read Yelp API keys
with io.open('config_secret.json') as cred:
creds = json.load(cred)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
# Set term as restaurant to get restaurants for results
# Need to pass in offset, so Yelp knows how much to offset by
params = {
'term': 'restaurant',
'offset': offset
}
return client.search(city, **params)
示例14: API_adapter
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
class API_adapter(object):
def __init__(self):
'''
Load Oauth keys
'''
_path_ = os.path.abspath(os.path.dirname(sys.argv[0]))
_path_ = '/'.join([_path_,'web_app/api_adapter/config_secret.json'])
cred = io.open(_path_)
cred = json.load(cred)
auth = Oauth1Authenticator(**cred)
self.client = Client(auth)
def get_restaurant(self, location, category_filter=None):
params = {
'term': 'food',
'location': location,
'cc' : 'US'
}
if category_filter:
params['category_filter'] = category_filter
restaurant = self.client.search(**params)
return restaurant.businesses
示例15: get_yelp
# 需要导入模块: from yelp.client import Client [as 别名]
# 或者: from yelp.client.Client import search [as 别名]
def get_yelp(city, job):
res = []
with open('yelp.json') as cred:
creds = load(cred)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
results = client.search(city, **{
'term': job,
'lang': 'fr',
'sort': 2
}).businesses
for result in results:
res.append({
"name": result.name,
"rating": result.rating,
"longitude": result.location.coordinate.longitude,
"latitude": result.location.coordinate.latitude,
"street": result.location.address
})
return res