-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
60 lines (47 loc) · 1.75 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
from flask import Flask, jsonify, request, Response
from flask_cors import CORS
import os
import map_generator
app = Flask(__name__)
CORS(app)
@app.route('/api/map', methods=['GET'])
def get_map():
date = request.args.get("date")
if date:
with open(map_generator.CreateMap(date) , "r" , encoding="utf-8") as result:
return Response(result.read(), mimetype='text/html')
else:
return jsonify({"error": "No date provided"}), 400
@app.route('/api/map_now', methods=['GET'])
def get_mapnow():
filelist = os.listdir("./data")
filelist.sort()
date = filelist[-1].split(".")[0]
if date:
with open(map_generator.CreateMap(date) , "r" , encoding="utf-8") as result:
return Response(result.read(), mimetype='text/html')
else:
return jsonify({"error": "No date provided"}), 400
@app.route('/', methods=['GET'])
def index():
with open("./index.html" , "r" , encoding="utf-8") as result:
return Response(result.read(), mimetype='text/html')
@app.route('/api/station_info', methods=['GET'])
def station_info():
with open("./station_info.json" , "r" , encoding="utf-8") as result:
return jsonify(result.read())
@app.route('/api/get_data', methods=['GET'])
def get_data():
date = request.args.get("date")
with open(f"./data/{date}.json" , "r" , encoding="utf-8") as result:
return jsonify(result.read())
@app.route('/api/get_time' , methods=["GET"])
def get_time():
filelist = os.listdir("./data")
filelist.sort()
return jsonify({"time":[file.split(".")[0] for file in filelist]})
if __name__ == '__main__':
maplist = os.listdir("./map")
for file in maplist:
os.remove(f"./map/{file}")
app.run(debug=True)