-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (26 loc) · 863 Bytes
/
main.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
from threading import Thread
import asyncio
from utlis.app import app, db
from utlis.data import update_data
from utlis.typical_case import add_typicals
from utlis.websocket import WebSocketServer
async def handle_data():
websocket = WebSocketServer()
await websocket.start_server()
while True:
with app.app_context():
new_data = update_data()
if len(new_data) > 0:
websocket.set_message(new_data)
await asyncio.sleep(60)
def start_handle_data():
asyncio.run(handle_data())
async def main():
with app.app_context():
db.create_all()
add_typicals(db, ["10.117.251.70", "10.117.251.71"])
data_thread = Thread(target=start_handle_data, name="handle_data")
data_thread.start()
app.run(host="0.0.0.0")
if __name__ == "__main__":
asyncio.run(main())