-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.py
99 lines (83 loc) · 2.8 KB
/
run.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
from datetime import datetime
import dateutil.parser
import tornado.ioloop
import tornado.web
from edb_converter import converter
from starcharts import sky_area
from starcharts.coord_calc import CoordCalc
from starcharts.diagram import Diagram
from starcharts.input_file import InputFile
class MainHandler(tornado.web.RequestHandler):
def get(self):
(
date,
lat,
lon,
elevation,
mag_min,
mag_max,
skyculture,
color,
frame_enabled,
frame_width,
frame_color,
) = self.get_query_strings()
new_catalog = converter.convert(date, lat, lon, elevation)
input_file = InputFile(new_catalog)
area = sky_area.SKY_AREA_CUSTOM
area.mag_min = mag_min
area.mag_max = mag_max
star_data_list = input_file.get_stars(area)
cc = CoordCalc(star_data_list, area, 500)
cc.process()
d = Diagram(
area,
star_data_list,
skyculture,
color,
frame_enabled,
frame_width,
frame_color,
)
list(map(d.add_curve, cc.calc_curves()))
svg_file = d.get_svg()
self.set_header("Content-Type", "image/svg+xml")
self.write("".join(svg_file))
def get_query_strings(self):
today_utc = datetime.utcnow().isoformat()
date_argument = str(self.get_argument("date", today_utc, strip=True))
parsed_date = dateutil.parser.parse(date_argument)
date = parsed_date.strftime("%Y/%m/%d %H:%M:%S")
lat = str(self.get_argument("lat", "41.015137", strip=True))
lon = str(self.get_argument("lon", "28.979530", strip=True))
elevation = int(self.get_argument("elevation", 0, strip=True))
mag_min = int(self.get_argument("mag_min", 4, strip=True))
mag_max = int(self.get_argument("mag_max", 0, strip=True))
skyculture = str(self.get_argument("skyculture", "western", strip=True))
color = str(self.get_argument("color", "black", strip=True))
frame_enabled = self.get_argument("frame_enabled", "True", strip=True) == "True"
frame_width = int(self.get_argument("frame_width", 4, strip=True))
frame_color = str(self.get_argument("frame_color", "black", strip=True))
return (
date,
lat,
lon,
elevation,
mag_min,
mag_max,
skyculture,
color,
frame_enabled,
frame_width,
frame_color,
)
def make_app():
return tornado.web.Application(
[
(r"/", MainHandler),
]
)
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()