added detection delay feature for preventing bulk record generation

added headers and API Key parts
Changes to be committed:
	modified:   camera-client/camera_monitor.py
This commit is contained in:
2023-09-21 23:02:01 +03:30
parent 9d4750d37d
commit 0cf729e90e

View File

@@ -12,6 +12,7 @@ class CameraMonitor:
def __init__(self, config, logger):
self.config = config
self.logger = logger
self.last_detection = 0
def initialize_camera(self):
"""
@@ -27,18 +28,32 @@ class CameraMonitor:
Log a scene change notification to the Scenesense server.
"""
current_time = int(time.time())
human_readable_time = datetime.utcfromtimestamp(current_time).strftime('%Y-%m-%d %H:%M:%S')
human_readable_time = datetime.utcfromtimestamp(
current_time
).strftime('%Y-%m-%d %H:%M:%S')
description = f'Scene change detected at {human_readable_time}'
payload = {'timestamp': current_time, 'description': description}
try:
response = requests.post(self.config['api_url'], json=payload)
response.raise_for_status()
self.logger.info(f'Scene change logged: {description}')
except requests.exceptions.RequestException as e:
self.logger.error(f'Error connecting to Scenesense server: {e}')
except requests.exceptions.HTTPError as e:
self.logger.error(f'HTTP error: {e}')
payload = {
'timestamp': current_time,
'description': description
}
headers = {
'Authorization': self.config['api_key']
}
if (
current_time - self.last_detection >= self.config['detection_delay']
):
try:
response = requests.post(
self.config['api_url'],
json=payload,
headers=headers
)
response.raise_for_status()
self.logger.info(f'Scene change logged: {description}')
except requests.exceptions.RequestException as e:
self.logger.error(f'Error connecting to Scenesense server: {e}')
except requests.exceptions.HTTPError as e:
self.logger.error(f'HTTP error: {e}')
def detect_scene_change(self, previous_frame, current_frame):
"""