-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (30 loc) · 1.14 KB
/
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
39
from photo import take_photo
from logic import is_door_locked, is_business_hours
import time
from picamera import PiCamera
import os
from slack_integration import send_slack_message, check_slack
# initialize the camera
camera = PiCamera()
# check if we should send slack messages
send_messages = check_slack()
while True:
image = take_photo(camera)
is_locked = is_door_locked(image=image)
if is_locked is None:
print("Couldn't determine if the door is locked")
elif is_locked is not None:
if is_locked and is_business_hours():
print(
"The door is locked and it's business hours, someone should unlock it"
)
elif not is_locked and not is_business_hours():
message = "The door is unlocked and it's not business hours, someone should lock it"
print(message)
# send the message to slack as we shouldn't leave the door unlocked after hours
if send_messages:
send_slack_message(message=message)
else:
print("Everything is fine!")
# sleep for 5 minutes before checking again
time.sleep(5 * 60)