-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
94 lines (64 loc) · 2.76 KB
/
server.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
"""Flask web server for my heavens app."""
# Copyright (c) 2017 Bonnie Schulkin
# This file is part of My Heavens.
# My Heavens is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# My Heavens is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
# You should have received a copy of the GNU Affero General Public License
# along with My Heavens. If not, see <http://www.gnu.org/licenses/>.
import os
from flask import Flask, request, render_template, jsonify
from model import connect_to_db, Constellation
from starfield import StarField
from stars import get_stars, get_constellations
from definitions import DEFINITIONS
# display radius
STARFIELD_RADIUS = 400
app = Flask(__name__)
@app.route('/')
def display_chart():
"""display the basic html for the star field.
Stars will be filled in with js"""
return render_template("main.html",
sorted_terms=sorted(DEFINITIONS.keys()),
terms=DEFINITIONS)
@app.route('/terms.json')
def return_terms():
"""Return json of terms, definitions, and wikipedia links."""
return jsonify(DEFINITIONS)
@app.route('/stars.json')
def return_stars():
"""return a json of star and constellation info
"""
max_magnitude = 4.5 # dimmest stars to show
return jsonify({'constellations': get_constellations(),
'stars': get_stars(max_magnitude)})
@app.route('/place-time-data.json', methods=['POST'])
def return_place_time_data():
"""Return json of sky rotation, planet, sun and moon info.
Returned data is based on location and time from POST data.
"""
lat = request.form.get('lat')
lng = request.form.get('lng')
localtime_string = request.form.get('datetime')
max_magnitude = 5 # dimmest planets to show
stf = StarField(lat=float(lat),
lng=float(lng),
max_mag=max_magnitude,
localtime_string=localtime_string)
return jsonify({'dateloc': stf.get_specs(),
'rotation': stf.get_sky_rotation(),
'planets': stf.get_planets(),
'sundata': stf.get_sun(), # sun is a reserved word in js!
'moon': stf.get_moon()})
if __name__ == '__main__':
# app.debug = True
connect_to_db(app)
# Use the DebugToolbar
# DebugToolbarExtension(app)
app.run(port=5005)