Fixed datetime bug
This commit is contained in:
parent
4ec4531f86
commit
fc63499bf0
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
import json
|
||||
from time import sleep
|
||||
from datetime import datetime, timedelta
|
||||
import datetime as dt
|
||||
|
||||
import requests
|
||||
import paho.mqtt.client as mqtt
|
||||
|
@ -24,8 +23,8 @@ class FrigateEventNotifier:
|
|||
self.last_notification_time = {}
|
||||
|
||||
def send_notification(self, event_id, camera, object_label, score, priority=3):
|
||||
now = datetime.now()
|
||||
if now - self.last_notification_time.get(camera, datetime.min) >= timedelta(seconds=self.quiet_period):
|
||||
now = dt.datetime.now()
|
||||
if now - self.last_notification_time.get(camera, dt.datetime.min) >= dt.timedelta(seconds=self.quiet_period):
|
||||
# Quiet period has passed since the last notification for this camera
|
||||
self.last_notification_time[camera] = now
|
||||
camera_location = ' '.join(word.capitalize() for word in camera.split('_'))
|
||||
|
|
|
@ -4,7 +4,7 @@ import json
|
|||
import time
|
||||
import traceback
|
||||
from threading import Thread
|
||||
from datetime import datetime, time, timedelta
|
||||
import datetime as dt
|
||||
|
||||
import requests
|
||||
from flask import Blueprint, request, jsonify
|
||||
|
@ -14,23 +14,23 @@ import paho.mqtt.publish as mqtt_publish
|
|||
blueprint = Blueprint('detection', __name__)
|
||||
|
||||
|
||||
def get_sunset() -> datetime:
|
||||
sunset_date = datetime.now().date()
|
||||
def get_sunset() -> dt.datetime:
|
||||
sunset_date = dt.datetime.now().date()
|
||||
try:
|
||||
IPGEOLOCATION_API_KEY = os.environ['IPGEOLOCATION_API_KEY']
|
||||
ipgeolocation_api_response = requests.get(f'https://api.ipgeolocation.io/astronomy?apiKey={IPGEOLOCATION_API_KEY}&location=Winter+Haven,+FL')
|
||||
ipgeolocation_api_response.raise_for_status()
|
||||
|
||||
astronomical_json = json.loads(ipgeolocation_api_response.content)
|
||||
sunset_time = datetime.strptime(astronomical_json['sunset'], '%H:%M').time()
|
||||
sunset_time = dt.datetime.strptime(astronomical_json['sunset'], '%H:%M').time()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
sunset_time = time(20, 00, 00)
|
||||
sunset_time = dt.time(20, 00, 00)
|
||||
finally:
|
||||
if sunset_time < datetime.now().time():
|
||||
if sunset_time < dt.datetime.now().time():
|
||||
# Sunset has already passed today
|
||||
sunset_date += timedelta(days=1)
|
||||
return datetime.combine(sunset_date, sunset_time)
|
||||
sunset_date += dt.timedelta(days=1)
|
||||
return dt.datetime.combine(sunset_date, sunset_time)
|
||||
|
||||
|
||||
def reset_all_camera_detection_at_sunset() -> None:
|
||||
|
@ -43,7 +43,7 @@ def reset_all_camera_detection_at_sunset() -> None:
|
|||
|
||||
sunset = get_sunset()
|
||||
print(f'Waiting until {sunset} to reset detection for all cameras...', file=sys.stderr)
|
||||
seconds_until_sunset = (sunset - datetime.now()).total_seconds()
|
||||
seconds_until_sunset = (sunset - dt.datetime.now()).total_seconds()
|
||||
time.sleep(seconds_until_sunset)
|
||||
|
||||
for camera_name in frigate_camera_config:
|
||||
|
|
Loading…
Reference in New Issue