-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (44 loc) · 1.3 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
from fastapi import FastAPI
from helper import update, get
from apscheduler.schedulers.background import BackgroundScheduler
import time
import logging
app = FastAPI()
logger = logging.getLogger("uvicorn.error")
logger.setLevel(logging.INFO)
def scheduledjob():
logger.info(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - Checking Price")
update()
scheduler = BackgroundScheduler()
scheduler.add_job(scheduledjob, 'interval', hours=1)
scheduler.start()
@app.on_event("startup")
def startup_event():
logger.info(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - Started")
update()
@app.get("/update")
def root():
updated = update()
msg = "Updated nothing"
if updated[0] and updated[1]:
msg = "Updated ABC & Deinze"
return {"message": msg}
if updated[0] and not updated[1]:
msg = "Updated ABC"
return {"message": msg}
if not updated[0] and updated[1]:
msg = "Updated Deinze"
return {"message": msg}
return {"message": msg}
@app.get("/price")
def root():
price = get()
if 'null' not in price:
return {
"abc": price[0],
"deinze": price[1]
}
return {"error": "some data is missing"}
@app.on_event("shutdown")
def shutdown_event():
scheduler.shutdown()