-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreq3.py
237 lines (193 loc) · 6.6 KB
/
req3.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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'
]
all_restaurant_types = restaurant_types + cuisine_types + specific_food_types + meal_types + specialty_types
#veridon goes here
def get_specific(name, adress, lat, long):
str=veridon(name, address, lat, long)
all_specialties=[]
for specialty in all_restaurant_types:
if specialty in str:
all_specialties.append(specialty)
return all_specialties
#find given restaurant in veridon, return all the strings that match with specificsm return list of strings
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', [])
all_stations = [];
for station in transit_results:
station_info = {
'name': station.get('name', 'N/A'),
'address': station.get('vicinity', 'N/A'),
}
all_stations.append(station_info)
# Count the number of transit stations
return all_stations
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', [])
# List to store information about all restaurants
all_restaurants = []
#nm = place.get('name', 'N/A')
#adr = place.get('vicinity', 'N/A')
# Process each restaurant and save relevant information
for place in places_results:
restaurant_info = {
'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'),
'latitude': place['geometry']['location']['lat'],
'longitude': place['geometry']['location']['lng'],
'types': place.get('types', []),
'transit_count': count_transit_stations(api_key, place['geometry']['location']['lat'], place['geometry']['location']['lng']),
'specifics': get_specific('name', 'address', latitude, longitude)
}
# Map price level to a more human-readable format
price_mapping = {0: 'Free', 1: 'Inexpensive', 2: 'Moderate', 3: 'Expensive', 4: 'Very Expensive'}
restaurant_info['price_range'] = price_mapping.get(restaurant_info['price_level'], 'N/A')
# Add the restaurant information to the list
all_restaurants.append(restaurant_info)
return all_restaurants
def model(restaurants, stations, specific, location, price):
ans=0
for rest in restaurants:
ans=ans+restaurants['rating']/5*((4-abs(price-rest['price_range'])))
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'])
nearby_restaurants = get_nearby_restaurants(api_key, location['lat'], location['lng'])
# Print the information about all restaurants
for idx, restaurant in enumerate(nearby_restaurants, 1):
print(f"\nRestaurant {idx}:")
print(f"Name: {restaurant['name']}")
print(f"Address: {restaurant['address']}")
print(f"Rating: {restaurant['rating']}")
print(f"Price Range: {restaurant['price_range']}")
print(f"Latitude: {restaurant['latitude']}")
print(f"Longitude: {restaurant['longitude']}")
print(f"Types: {', '.join(restaurant['types'])}")
#print(f"transit_count: {restaurant['transit_count']}")
nearby_stations = count_transit_stations(api_key, location['lat'], location['lng'])
for idx, station in enumerate(nearby_stations, 1):
print(f"\nStation {idx}:")
print(f"Name: {station['name']}")
print(f"Adresa: {station['address']}")
my_specific=input("ce specific vrei? ")
my_price=input("ce pret range vrei? ")
score=model(nearby_restaurants, nearby_stations, my_specific, location, my_price)
#print(count_transit_stations(api_key, location['lat'], location['lng']))