-
Notifications
You must be signed in to change notification settings - Fork 17
/
restaurant_info.py
64 lines (42 loc) · 1.57 KB
/
restaurant_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests
import json
from config import yelp_api_key
class Location:
def __init__(self, name, location):
self.name = name
self.location = location
def make_api_call(self):
host = 'https://api.yelp.com'
path = '/v3/businesses/search'
# Yelp Authorization Header with API Key
headers = {
'Authorization': 'Bearer {}'.format(yelp_api_key)
}
url_params = {
'term': self.name.replace(' ', '+'),
'location': self.location.replace(' ', '+'),
'limit': 10
}
url_params = url_params or {}
url = '{}{}'.format(host, path)
response = requests.get(url, headers=headers, params=url_params).json()
return response
def validate_business(self):
response = self.make_api_call()
# Set state to False in case no Yelp match found
state = False
possible_matches = []
try:
# Check search returns for match with business
for i in range(len(response['businesses'])):
# If match found:
if response['businesses'][i]['name'] == self.name:
return response['businesses'][0]
state = True
except:
print('Venue not found, please enter a valid venue')
def lat_long(self):
r = self.validate_business()
#return (response['businesses'][0])
lat, long = r['coordinates']['latitude'], r['coordinates']['longitude']
return lat, long