-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
71 lines (59 loc) · 1.41 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask
from flask import render_template, jsonify
from info import data
from stream_code import main
import threading
class Thread (threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
main()
# create application
app = Flask(__name__)
prev_list = list()
@app.route('/')
def index():
t = Thread()
t.start()
return render_template('index.html')
@app.route('/data')
def stream_data():
'''
GeoJSON Format
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
'''
geo_data = []
for item in data:
geo_item = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": item['coordinates']['coordinates']
},
"properties": {
"name": item["text"]
},
}
geo_data.append(geo_item)
global prev_list
if prev_list == []:
prev_list = geo_data[:]
return jsonify(geo_data)
else:
d = []
for item in geo_data:
if item not in prev_list:
d.append(item)
prev_list = geo_data[:]
return jsonify(d)
if __name__ == "__main__":
app.run(debug=True, threaded=True, host="0.0.0.0")