本文整理汇总了Python中yelp.client.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_random_bar_coords
def get_random_bar_coords(lat, lon, radius):
mpm = 1609.34 # meters per mile
config = json.load(open('conf.json', 'rb'))
auth = Oauth1Authenticator(
consumer_key=config['yelp']['consumer_key'],
consumer_secret=config['yelp']['consumer_secret'],
token=config['yelp']['token'],
token_secret=config['yelp']['token_secret']
)
client = Client(auth)
param_offset = lambda x: {
'term': 'bars, All',
'lang': 'en',
'sort': 2, # 2: only the top rated in the area
'radius_filter': int(radius * mpm),
'offset': x
}
bus_list = []
for offset in [0, 20]:
response = client.search_by_coordinates(lat, lon, **param_offset(offset))
bus_list.extend(response.businesses)
bar = random.choice(bus_list)
while bar.name in ["Peter's Pub", "Hemingway's Cafe"]: # Can we just
bar = random.choice(bus_list)
return bar.location.coordinate.latitude, bar.location.coordinate.longitude
示例2: call_yelp
def call_yelp(midlat,midlong,radius):
auth = Oauth1Authenticator(
consumer_key='Qas4yX9C4dXU-rd6ABmPEA',
consumer_secret='5Rtb9Gm5KuwRHSevprdb450E37M',
token='xBq8GLMxtSbffTWPPXx7au7EUd2ed3MO',
token_secret='Nee0b14NkDO9uSX5cVsS7c4j6GQ'
)
print radius
client = Client(auth)
params = {
'term':'24 hour',
'sort':'0',
'radius_filter': str(radius) # 3 mi radius
}
#ex: response = client.search_by_coordinates(40.758895,-73.985131, **params)
response = client.search_by_coordinates(float(midlat),float(midlong), **params)
f = open('output_yelp.txt','w+')
for i in range(0,len(response.businesses)):
#f.write(response.businesses[i].name)
#f.write(",")
f.write('%f' % response.businesses[i].location.coordinate.latitude)
f.write(",")
f.write('%f' % response.businesses[i].location.coordinate.longitude)
f.write("\n")
f.close()
示例3: Yelp
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)
示例4: post_detail
def post_detail(request, photo_id):
try:
# get Flickr Post details
post = FlickrPost.objects.get(pk=photo_id)
context_dict['valid_post'] = True
h = html.parser.HTMLParser()
if not post.latitude or not post.longitude:
photo = __get_flickr_post_info(photo_id)
post.latitude = float(photo['location']['latitude'])
post.longitude = float(photo['location']['longitude'])
post.description = h.unescape(photo['description']['_content'])
post.save()
context_dict['post'] = post
# get Yelp reviews for that location
yelp = YelpClient.objects.get(pk=1)
auth = Oauth1Authenticator(
consumer_key=yelp.consumer_key,
consumer_secret=yelp.consumer_secret,
token=yelp.token,
token_secret=yelp.token_secret
)
client = Client(auth)
# get location that most closely matches the geolocation
best_business = None
alt_businesses = list()
yelp_api_error = False
try:
response = client.search_by_coordinates(post.latitude, post.longitude)
if response.businesses:
best_business = response.businesses[0]
if len(response.businesses) > 5:
alt_businesses = response.businesses[1:6]
elif len(response.businesses) > 1:
alt_businesses = response.businesses[1:]
except:
yelp_api_error = True
context_dict['yelp_api_error'] = yelp_api_error
context_dict['best_business'] = best_business
context_dict['alt_businesses'] = alt_businesses
except FlickrPost.DoesNotExist:
context_dict['valid_post'] = False
return render(request, 'entree/post_detail.html', context_dict)
示例5: api_callee
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
示例6: getRestaurants
def getRestaurants(latitude, longitude):
client = Client(auth)
params = {
'term': 'food',
'lang': 'en',
'radius_filter': 10000
}
response = client.search_by_coordinates(latitude, longitude, **params)
return response.businesses
示例7: fetchCoffeeBusinesses
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
示例8: get_total_ratings
def get_total_ratings(x):
# authenticate the api
auth = Oauth1Authenticator(
consumer_key='d8eoj4KNoPqOqE_RN9871Q',
consumer_secret='pGVDNEGSaH8Kv-WZ8ba5v02IjCo',
token='S-SfyVte5G0nCkTmbydWRtxlheNXCEnG',
token_secret='Y_UViE9LthLQqW7_ht8U8V_F6aE'
)
client = Client(auth)
# return the total number of ratings for a restaurant
total_ratings = client.get_business(x)
total_ratings = total_ratings.business.review_count
return total_ratings
示例9: get_results
def get_results(params):
# read API keys
with open('config_secret.json') as cred:
creds = json.load(cred)
auth = Oauth1Authenticator(**creds)
client = Client(auth)
request = client.search_by_coordinates("http://api.yelp.com/v2/search",params=params)
#Transforms the JSON API response into a Python dictionary
data = request.json()
client.close()
return data
示例10: Add_nodes
def Add_nodes(city_name = 'San_Francisco', buss_type = 'Restaurants' , number = 100):
# Ussing the Yelp library for Yelp authentification and requesting info
auth = Oauth1Authenticator(
consumer_key="",
consumer_secret="",
token="",
token_secret=""
)
client = Client(auth)
buss_types = make_sure('buss_types')
assert buss_type in buss_types.keys()
locations = find_locations(city_name,number)
if os.path.isfile('Data/{}_Data.json'.format(city_name)) == False:
with open('Data/{}_Data.json'.format(city_name),'w') as f:
geojson.dump({"type": "FeatureCollection","features": []}, f)
with open('Data/{}_Data.json'.format(city_name)) as f:
data = json.load(f)
IDs = []
added = 0
nodes_added = []
for feature in [feature for feature in data['features'] if feature['geometry']['type'] == 'point']:
IDs.append(feature['properties']['name'])
for lat,long in locations:
places = client.search_by_coordinates(lat, long, buss_type)
for business in places.businesses:
if business.name not in IDs:
IDs.append(business.name)
node = Node(business.name, business.location.coordinate.latitude, business.location.coordinate.longitude, business.rating,
buss_type, business.categories, business.image_url, city_name, comp_time = buss_types[buss_type]['durations'])
data['features'].append(node.geo_interface())
nodes_added.append(node)
added += 1
with open('Data/{}_Data.json'.format(city_name), 'w') as f:
geojson.dump(data, f)
return '{} nodes added'.format(added)
示例11: search_yelp
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'
});
示例12: get
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,
}
示例13: YelpService
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
示例14: __init__
def __init__(self):
auth = Oauth1Authenticator(
consumer_key= 'NqKErS1dFKKwfxlc5KpB0Q',
consumer_secret= 'BzO_xc7Jge-B5YeysLuLi-WkiHE',
token= '72CDWmpOaC8LEVgjY1bZVQgyX4v3v8fx',
token_secret='yLfQC1-Vr_B5mpuqKtidnK_gnbo'
)
self.client = Client(auth)
示例15: get_businesses_from_yelp
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