-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.py
64 lines (52 loc) · 1.88 KB
/
alert.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
""" Para obtener el id del chat, se tiene que enviar un mensaje al chat del bot y acceder a
https://api.telegram.org/bot{{api_token}}/getUpdates
"""
from sys import exit as terminate
from services.camera_service import CameraService
from services.os_service import OSService
from services.thread_service import ThreadService
from utils.retry import retry
from services.telegram_service import TelegramService
from utils.utils import get_global_ip, get_warning_message
RETRIES = None
TIME_OUT = 5
thread_service = ThreadService()
get_global_ip_retry = retry(RETRIES, TIME_OUT)(get_global_ip)
process_response = thread_service.create_thread(get_global_ip_retry)
if not process_response:
terminate(1)
global_ip = process_response.content.decode()
os_service = OSService()
tlg_service = TelegramService(
os_service.get_environ("tlg_api_key"),
os_service.get_environ("chat_id")
)
send_with_retry = retry(RETRIES, TIME_OUT)(tlg_service.send_message)
try:
send_with_retry(get_warning_message(global_ip))
except Exception:
raise
get_updates_with_retry = retry(RETRIES, TIME_OUT)(tlg_service.process_updates)
try:
action = get_updates_with_retry()
print(f"Action: {action}")
send_photo_with_retry = retry(RETRIES, TIME_OUT)(tlg_service.send_photo)
if action == "safe":
terminate(0)
elif action == "photo":
os_service.set_environ("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0")
camera_service = CameraService(os_service.get_environ("photo_name"))
photo = camera_service.take_photo()
try:
send_photo_with_retry(photo)
except Exception:
raise
elif action == "capture":
capture = os_service.get_screen_shot()
send_photo_with_retry(capture)
elif action == "lock":
os_service.lock_screen()
elif action == "turn_off":
os_service.turn_off()
except Exception:
raise