main.py
9.76 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
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
from __future__ import print_function
import datetime
import os
import pytz
import voeventparse as vp
import jinja2
import uuid
from flask import Flask, render_template, request, flash
from forms import ContactForm , ContactFormLunar, ContactFormComet
app =Flask(__name__)
app.secret_key = 'development key'
@app.route('/')
def home():
return render_template('home.html')
@app.route('/fireball', methods=['GET', 'POST'])
def index():
form = ContactForm()
if request.method == 'POST':
if form.validate() == False:
flash('An error occured : the form was not validated.')
return render_template('index.html', form=form)
else:
voevent_id = uuid.uuid4()
# Get the date
date=str(datetime.datetime.strptime(request.form['DateTime'],"%Y-%m-%d %H:%M:%S"))
my_datetime=date[0:10]+"T"+date[11:19]
# Set the basic packet ID and Author details
templateLoader = jinja2.FileSystemLoader( searchpath="/" )
templateEnv = jinja2.Environment( loader=templateLoader )
TEMPLATE_FILE = "/tmp/voevent-fireball.xml"
template = templateEnv.get_template( TEMPLATE_FILE )
# using dictionary to fill information
# case of what list [value, datatype, ucd]
my_list_what={"event_type":['giant planet fireball','string','meta.flag'],
"event_status":['finished','string','meta.flag']}
my_groupname='target'
my_list_groupname = [{"longitude":[request.form['Llongitude'],'float','pos.bodyrc.lon','deg'],
"latitude":[request.form['Llatitude'],'float','pos.bodyrc.lat','deg']}]
my_groupname_source='source'
my_list_groupname_source = [{"target_class":['comet','string','meta.id'],
"target_name":[request.form['comet'],'string','meta.id'],
"target_region":['trail','string','meta.id']}]
my_list_wherewhen_target={"target_name":"67P",
"target_class":"comet",
"target_region":"tail"}
my_list_wherewhen_time={"time_obs":"2017-02-24T11:07:28.1Z",
"time_scale":"UTC",
"target_origin":"Earth"}
my_list_how_instrument={"instrument_description":request.form['instrument']}
# one dictionary for all field description
my_list_description = {"what":request.form['description']}
output_filename = '/var/tmp/new_voevent.xml'
new_voevent = open(output_filename,'w')
new_voevent.write(template.render(voevent_id=voevent_id,
my_shortname=request.form['shortname'],
my_contactname=request.form['observer'],
my_contactphone=request.form['phone'],
my_contactemail=request.form['mail'],
my_datetime=my_datetime,
my_city=request.form['city'],
my_country=request.form['country'],
my_list_what=my_list_what,
my_list_wherewhen_target=my_list_wherewhen_target,
my_list_wherewhen_time=my_list_wherewhen_time,
my_list_how_instrument=my_list_how_instrument,
my_list_description=my_list_description,
my_groupname_source=my_groupname_source,
my_list_groupname_source=my_list_groupname_source,
my_groupname=my_groupname,
my_list_groupname=my_list_groupname))
print("Wrote your voevent to ", os.path.abspath(output_filename))
return render_template('success.html')
elif request.method == 'GET':
return render_template('index.html', form=form)
@app.route('/lunarflash', methods=['GET', 'POST'])
def indexlunar():
form = ContactFormLunar()
if request.method == 'POST':
if form.validate() == False:
flash('An error occured : the form was not validated.')
return render_template('index-lunar.html', form=form)
else:
voevent_id = uuid.uuid4()
# Get the date
date=str(datetime.datetime.strptime(request.form['DateTime'],"%Y-%m-%d %H:%M:%S"))
my_datetime=date[0:10]+"T"+date[11:19]
# Set the basic packet ID and Author details
templateLoader = jinja2.FileSystemLoader( searchpath="/" )
templateEnv = jinja2.Environment( loader=templateLoader )
TEMPLATE_FILE = "/tmp/voevent-lunar.xml"
template = templateEnv.get_template( TEMPLATE_FILE )
# using dictionary to fill information
# case of what list [value, datatype, ucd]
my_list_what={"event_type":['detection','string','meta.flag'],
"event_status":['finished','string','meta.flag']}
my_groupname='target'
my_list_groupname = [{"longitude":[request.form['Llongitude'],'float','pos.bodyrc.lon','deg'],
"latitude":[request.form['Llatitude'],'float','pos.bodyrc.lat','deg']}]
my_groupname_source='source'
my_list_groupname_source = [{"target_class":['asteroid','string','meta.id'],
"target_name":[request.form['comet'],'string','meta.id'],
"target_subclass":['neo','string','meta.id']}]
my_list_wherewhen_target={"target_name":"67P",
"target_class":"comet",
"target_region":"tail"}
my_list_wherewhen_time={"time_obs":"2017-02-24T11:07:28.1Z",
"time_scale":"UTC",
"target_origin":"Earth"}
my_list_how_instrument={"instrument_description":request.form['instrument']}
# one dictionary for all field description
my_list_description = {"what":request.form['description']}
output_filename = '/var/tmp/new_voevent.xml'
new_voevent = open(output_filename,'w')
new_voevent.write(template.render(voevent_id=voevent_id,
my_shortname=request.form['shortname'],
my_contactname=request.form['observer'],
my_contactphone=request.form['phone'],
my_contactemail=request.form['mail'],
my_datetime=my_datetime,
my_city=request.form['city'],
my_country=request.form['country'],
my_list_what=my_list_what,
my_list_wherewhen_target=my_list_wherewhen_target,
my_list_wherewhen_time=my_list_wherewhen_time,
my_list_how_instrument=my_list_how_instrument,
my_list_description=my_list_description,
my_groupname_source=my_groupname_source,
my_list_groupname_source=my_list_groupname_source,
my_groupname=my_groupname,
my_list_groupname=my_list_groupname))
print("Wrote your voevent to ", os.path.abspath(output_filename))
return render_template('success.html')
elif request.method == 'GET':
return render_template('index-lunar.html', form=form)
@app.route('/comettail', methods=['GET', 'POST'])
def indexcomet():
form = ContactFormComet()
if request.method == 'POST':
if form.validate() == False:
flash('An error occured : the form was not validated.')
return render_template('index-comet.html', form=form)
else:
voevent_id = uuid.uuid4()
# Get the date
date=str(datetime.datetime.strptime(request.form['DateTime'],"%Y-%m-%d %H:%M:%S"))
my_datetime=date[0:10]+"T"+date[11:19]
# Set the basic packet ID and Author details
templateLoader = jinja2.FileSystemLoader( searchpath="/" )
templateEnv = jinja2.Environment( loader=templateLoader )
TEMPLATE_FILE = "/tmp/voevent-comet.xml"
template = templateEnv.get_template( TEMPLATE_FILE )
# using dictionary to fill information
# case of what list [value, datatype, ucd]
my_list_what={"event_type":['cometary tail disconection','string','meta.flag'],
"event_status":['onset','string','meta.flag']}
my_groupname='target'
my_list_groupname = [{"target_class":['comet','string','meta.id'],
"target_name":['67P','string','meta.id'],
"target_region":['Tail','string','meta.id']}]
my_list_wherewhen_target={"target_name":"67P",
"target_class":"comet",
"target_region":"tail"}
my_list_wherewhen_time={"time_obs":"2017-02-24T11:07:28.1Z",
"time_scale":"UTC",
"target_origin":"Earth"}
# one dictionary for all field description
my_list_description = {"what":"Tail disconnection of comet 67P"}
output_filename = '/var/tmp/new_voevent.xml'
new_voevent = open(output_filename,'w')
new_voevent.write(template.render(voevent_id=voevent_id,
my_shortname=request.form['shortname'],
my_contactname=request.form['observer'],
my_contactphone=request.form['phone'],
my_contactemail=request.form['mail'],
my_datetime=my_datetime,
my_city=request.form['city'],
my_country=request.form['country'],
my_list_what=my_list_what,
my_list_wherewhen_target=my_list_wherewhen_target,
my_list_description=my_list_description,
my_groupname=my_groupname,
my_list_groupname=my_list_groupname))
print("Wrote your voevent to ", os.path.abspath(output_filename))
return render_template('success.html')
elif request.method == 'GET':
return render_template('index-comet.html', form=form)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=80)