-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (34 loc) · 1.36 KB
/
app.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
import requests
import googlemaps
from flask import Flask, render_template, jsonify
API_KEY = 'AIzaSyA0np_qdbzooZ2asbRlO9MrQS_E4fPzknI'
gmaps = googlemaps.Client(key=API_KEY)
location = '43.6335025,-79.5240738' # Latitude and longitude of 180 Norseman
app = Flask(__name__)
@app.route('/')
def index():
return render_template('app.html')
@app.route('/executePythonScript')
def execute_python_script():
lst = []
radius = 6000 #meters
place_type = 'mosque'
places_result = gmaps.places_nearby(location=location, radius=radius, type=place_type)
for place in places_result['results']:
final = {}
final["masjid_name"] = place['name']
final["location"] = place['geometry']['location']
place_details = gmaps.place(place["place_id"])
if 'website' in place_details['result']:
final["url"] = place_details['result']['website']
else:
final["url"] = ""
distance_matrix = gmaps.distance_matrix(location, final["location"])
distance_in_meters = distance_matrix['rows'][0]['elements'][0]['distance']['value']
distance_in_kilometers = distance_in_meters / 1000
final["kilometers_away"] = distance_in_kilometers
lst.append(final)
lst = sorted(lst, key=lambda x: x['kilometers_away'])
return lst
if __name__ == '__main__':
app.run(debug=True)