import utils
from datetime import datetime
+
class any_camera_trigger(trigger.trigger):
def __init__(self):
self.triggers_in_the_past_seven_min = {
- "driveway" : 0,
- "frontdoor" : 0,
- "cabin_driveway" : 0,
- "backyard" : 0,
+ "driveway": 0,
+ "frontdoor": 0,
+ "cabin_driveway": 0,
+ "backyard": 0,
}
self.last_trigger = {
- "driveway" : 0,
- "frontdoor" : 0,
- "cabin_driveway" : 0,
- "backyard" : 0,
+ "driveway": 0,
+ "frontdoor": 0,
+ "cabin_driveway": 0,
+ "backyard": 0,
}
def choose_priority(self, camera, age):
base_priority_by_camera = {
- "driveway" : 1,
- "frontdoor" : 2,
- "cabin_driveway" : 1,
- "backyard" : 0,
+ "driveway": 1,
+ "frontdoor": 2,
+ "cabin_driveway": 1,
+ "backyard": 0,
}
priority = base_priority_by_camera[camera]
if age < 10:
def get_triggered_page_list(self):
triggers = []
cameras_with_recent_triggers = 0
- camera_list = [ "driveway",
- "frontdoor",
- "cabin_driveway",
- "backyard" ]
+ camera_list = ["driveway", "frontdoor", "cabin_driveway", "backyard"]
now = time.time()
try:
for camera in camera_list:
file = "/timestamps/last_camera_motion_%s" % camera
ts = os.stat(file).st_ctime
- if (ts != self.last_trigger[camera] and
- (now - ts) < 10):
+ if ts != self.last_trigger[camera] and (now - ts) < 10:
print("Camera: %s, age %s" % (camera, (now - ts)))
self.last_trigger[camera] = ts
cameras_with_recent_triggers += 1
# triggered at the same time.
for camera in camera_list:
if (now - self.last_trigger[camera]) < 10:
- if (self.triggers_in_the_past_seven_min[camera] <= 4 or
- cameras_with_recent_triggers > 1):
+ if (
+ self.triggers_in_the_past_seven_min[camera] <= 4
+ or cameras_with_recent_triggers > 1
+ ):
ts = utils.timestamp()
p = self.choose_priority(camera, age)
- print(("%s: ****** %s[%d] CAMERA TRIGGER ******" % (
- ts, camera, p)))
- triggers.append( ( "hidden/%s.html" % camera,
- self.choose_priority(camera, age)) )
+ print(
+ (
+ "%s: ****** %s[%d] CAMERA TRIGGER ******"
+ % (ts, camera, p)
+ )
+ )
+ triggers.append(
+ (
+ "hidden/%s.html" % camera,
+ self.choose_priority(camera, age),
+ )
+ )
else:
- print(("%s: Camera %s too spammy, squelching it" % (
- ts, camera)))
+ print(
+ ("%s: Camera %s too spammy, squelching it" % (ts, camera))
+ )
except Exception as e:
print(e)
pass
else:
return triggers
-#x = any_camera_trigger()
-#print(x.get_triggered_page_list())
+
+# x = any_camera_trigger()
+# print(x.get_triggered_page_list())