-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (95 loc) · 3.75 KB
/
main.py
File metadata and controls
105 lines (95 loc) · 3.75 KB
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
import operator
import requests
import pyrebase
from flask import Flask, render_template, request, session, url_for, redirect, flash
from flask_googlemaps import GoogleMaps, Map, icons
from geopy.distance import vincenty
# Initialize the app from Flask
app = Flask(__name__)
app.secret_key = 'secret_key'
config = {
"apiKey": "AIzaSyAouz-Hjy7z8fu-8zIlYs4Ay4tfLURAUYw",
"authDomain": "chalkitup-5b411.firebaseapp.com",
"databaseURL": "https://chalkitup-5b411.firebaseio.com",
"storageBucket": "chalkitup-5b411.appspot.com",
"messagingSenderId": "933786712703"
}
firebase = pyrebase.initialize_app(config)
app.config['GOOGLEMAPS_KEY'] = "AIzaSyA7PFRZw7yC2TcwR0Rm8k8V0l-MSZt4aRk"
GoogleMaps(app)
@app.route('/', methods=['GET', 'POST'])
def index():
"""
Return the home page for commUnity that displays about, download, team, and maps sections.
"""
db = firebase.database()
all_projects = db.child("Projects").get()
markers_list = [{
'icon': 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
'lat': 40.6939904,
'lng': -73.98656399999999,
'infobox': "Current Location"
}]
for project in all_projects.each():
name = project.val()['name']
description = project.val()['description']
latitude = project.val()['latitude']
longitude = project.val()['longitude']
markers_list.append({'icon': 'http://maps.google.com/mapfiles/ms/icons/red-dot.png',
'lat': latitude,
'lng': longitude,
'infobox': ("Name: " + name + "<br/>Description: " + description)
})
community_map = Map(
identifier="community_map",
zoom=16,
lat=40.6939904,
lng=-73.98656399999999,
markers=markers_list,
scroll_wheel=False,
style="height:60%;width:100%;color:black;"
)
return render_template('index.html', community_map=community_map)
@app.route('/projects', methods=['GET', 'POST'])
def projects():
"""
Return the projects page that displays information for all projects based on distance.
"""
# Google Maps
db = firebase.database()
all_projects = db.child("Projects").get()
markers_list = [{
'icon': 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
'lat': 40.6939904,
'lng': -73.98656399999999,
'infobox': "Current Location"
}]
for project in all_projects.each():
name = project.val()['name']
description = project.val()['description']
latitude = project.val()['latitude']
longitude = project.val()['longitude']
markers_list.append({'icon': 'http://maps.google.com/mapfiles/ms/icons/red-dot.png',
'lat': latitude,
'lng': longitude,
'infobox': ("Name: " + name + "<br/>Description: " + description)
})
community_map = Map(
identifier="community_map",
zoom=16,
lat=40.6939904,
lng=-73.98656399999999,
markers=markers_list,
scroll_wheel=False,
style="height:60%;width:100%;color:black;"
)
# Project List
distances = {}
for project in all_projects.each():
current_location = (40.6939904, -73.98656399999999)
project_location = (project.val()['latitude'], project.val()['longitude'])
distances[project] = "{0:.1f}".format(vincenty(current_location, project_location).miles)
projects_by_distance = sorted(distances.items(), key=operator.itemgetter(1))
return render_template('projects.html', community_map=community_map, projects=projects_by_distance)
if __name__ == "__main__":
app.run('127.0.0.1', 5000, debug=True)