-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (54 loc) · 1.62 KB
/
main.py
File metadata and controls
64 lines (54 loc) · 1.62 KB
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
import asyncio
from datetime import datetime
from bot.bot_data import bot
from bot import *
from bot.help import help
from raspberry.read import read_dht
from raspberry.handle_data import save_data
from raspberry.events import check_conditions, generateReports, status_state
async def raspberry():
print("Leyendo sensores...")
i = 0
h_list = []
t_list = []
while True:
try:
h, t = await read_dht()
t_list.append(t)
h_list.append(h)
if i == 10:
h_list, t_list, i = await save_data(h_list, t_list, i)
except Exception as e:
print(e)
break
i += 1
async def reports():
current_time = datetime.now()
await generateReports(current_time)
await asyncio.sleep(5)
await reports()
async def conditions():
print("conditions")
h, t = await read_dht()
alert_sent = await check_conditions(h=h, t=t)
print(alert_sent)
if alert_sent:
print("checking condition in 30 min")
await asyncio.sleep(1800)
await status_state(False, 'alert_sent')
await conditions()
else:
print('conditions failed')
async def main():
print("Iniciando procesos...")
raspberry_task = asyncio.create_task(raspberry())
reports_task = asyncio.create_task(reports())
conditions_task = asyncio.create_task(conditions())
await bot.polling()
asyncio.gather(raspberry_task, reports_task, conditions_task)
if __name__ == "__main__":
print("Bot inicializado 🤖")
try:
asyncio.run(main())
except Exception as e:
print("\nBot finalizado")