-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreq2.py
178 lines (152 loc) · 4.57 KB
/
req2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import requests
restaurant_types = [
'restaurant',
'bar',
'cafe',
'night_club',
'pub',
'bakery',
'meal_delivery',
'meal_takeaway',
'liquor_store',
'grocery_or_supermarket',
'convenience_store',
'food',
'store',
'shopping_mall',
'department_store',
'supermarket',
'gas_station',
'pharmacy',
'book_store'
]
cuisine_types = [
'chinese',
'japanese',
'indian',
'italian',
'mexican',
'thai',
'french',
'greek',
'spanish',
'american',
'korean',
'vietnamese',
'mediterranean',
'middle_eastern',
'turkish',
'brazilian',
'peruvian',
'argentinian',
'moroccan',
'caribbean',
'african',
'hawaiian',
'filipino',
'asian',
'latin_american',
'cuban',
'russian',
'german',
'irish',
'british',
'australian',
'canadian'
]
specific_food_types = [
'pizza',
'sushi',
'burger',
'sandwich',
'ice_cream',
'donut',
'bakery',
'coffee_shop',
'juice_bar',
'smoothie',
'tea',
'ramen',
'noodle',
'hot_dog',
'frozen_yogurt'
]
meal_types = [
'breakfast',
'brunch',
'lunch',
'dinner'
]
specialty_types = [
'seafood',
'steakhouse',
'vegetarian',
'vegan',
'gluten_free',
'organic',
'farmers_market'
]
# Combine all types into a single list
all_restaurant_types = restaurant_types + cuisine_types + specific_food_types + meal_types + specialty_types
print(all_restaurant_types)
def count_transit_stations(api_key, latitude, longitude, radius=500, type='transit_station'):
endpoint_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
# Set up parameters for the Places API request
transit_params = {
'location': f'{latitude},{longitude}',
'radius': radius,
'type': type,
'key': api_key
}
# Make the Places API request
transit_response = requests.get(endpoint_url, params=transit_params)
transit_results = transit_response.json().get('results', [])
# Count the number of transit stations
transit_count = len(transit_results)
return transit_count
def get_nearby_restaurants(api_key, latitude, longitude, radius=500, keyword='restaurant'):
endpoint_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
# Set up parameters for the Places API request
places_params = {
'location': f'{latitude},{longitude}',
'radius': radius,
'keyword': keyword,
'key': api_key
}
# Make the Places API request
places_response = requests.get(endpoint_url, params=places_params)
places_results = places_response.json().get('results', [])
# Count transit stations for each restaurant and categorize the region
for place in places_results:
name = place.get('name', 'N/A')
address = place.get('vicinity', 'N/A')
rating = place.get('rating', 'N/A')
price_level = place.get('price_level', 'N/A')
# Map price level to a more human-readable format
price_mapping = {0: 'Free', 1: 'Inexpensive', 2: 'Moderate', 3: 'Expensive', 4: 'Very Expensive'}
price_range = price_mapping.get(price_level, 'N/A')
# Count transit stations for the region
transit_count = count_transit_stations(api_key, place['geometry']['location']['lat'], place['geometry']['location']['lng'])
# Categorize the region based on the number of transit stations
if transit_count >= 3:
region_type = 'Busy'
elif transit_count >= 1:
region_type = 'Moderate'
else:
region_type = 'Quiet'
print(f"Name: {name}, Address: {address}, Rating: {rating}, Price Range: {price_range}, Region Type: {transit_count}")
if __name__ == "__main__":
api_key = "AIzaSyCRuJ_aBmW-QqYPrVTY4hjDbZ8_DspaLZM"
location=input("Where would you like to open a restaurant? ")
address = location + " Bucuresti, Romania"
# Geocoding API endpoint
url = f"https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={api_key}"
# Make the request
response = requests.get(url)
data = response.json()
# Parse the response
if data['status'] == 'OK':
location = data['results'][0]['geometry']['location']
else:
print("Error:", data['status'])
get_nearby_restaurants(api_key, location['lat'], location['lng'])