This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.py
65 lines (50 loc) · 1.27 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
# app.py
from flask import Flask, request
from flask_cors import CORS
import json
import os
from refresh import update
from apscheduler.schedulers.background import BackgroundScheduler
port_ = 5000
interval_minutes = 10
app = Flask(__name__)
CORS(app)
def sensor():
update()
print("Scheduler is alive!")
sched = BackgroundScheduler(daemon=True)
sched.add_job(sensor,'interval',minutes=interval_minutes)
sched.start()
@app.route('/')
def index():
with open('data.json') as f:
d = json.load(f)
return d
@app.route('/confirmed')
def confirmed():
with open('data.json') as f:
d = json.load(f)
return d['confirmed']
@app.route('/deaths')
def deaths():
with open('data.json') as f:
d = json.load(f)
return d['deaths']
@app.route('/recovered')
def recovered():
with open('data.json') as f:
d = json.load(f)
return d['recovered']
@app.route('/latest')
def latest():
with open('data.json') as f:
d = json.load(f)
return d['latest']
@app.route('/updatedAt')
def updatedAt():
with open('data.json') as f:
d = json.load(f)
return d['updatedAt']
if __name__ == '__main__':
# Threaded option to enable multiple instances for multiple user access support
app.run(threaded=True, port=port_)