forked from Covid-19-Response-Greece/covid19-greece-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (41 loc) · 1.29 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
from flask import Flask, jsonify
from flask import abort
from flask import make_response
import json
import copy
app = Flask(__name__)
data_greece_JHCSSE = None
def init():
global data_greece_JHCSSE
with open('data/greece/JohnsHopkinsCSSE/timeseries_greece.json') as f:
data_greece_JHCSSE = json.load(f)['Greece']
@app.route('/all', methods=['GET'])
def get_all():
return jsonify({'cases': data_greece_JHCSSE})
@app.route('/confirmed', methods=['GET'])
def get_confirmed():
out_json = copy.deepcopy(data_greece_JHCSSE)
for date in out_json:
del date['recovered']
del date['deaths']
return jsonify({'cases': out_json})
@app.route('/recovered', methods=['GET'])
def get_recovered():
out_json = copy.deepcopy(data_greece_JHCSSE)
for date in out_json:
del date['confirmed']
del date['deaths']
return jsonify({'cases': out_json})
@app.route('/deaths', methods=['GET'])
def get_deaths():
out_json = copy.deepcopy(data_greece_JHCSSE)
for date in out_json:
del date['confirmed']
del date['recovered']
return jsonify({'cases': out_json})
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
if __name__ == '__main__':
init()
app.run(debug=True)