Enhance time synchronization checks, update storage paths, and improve camera recording management

This commit is contained in:
Alireza Vaezi
2025-07-25 22:38:33 -04:00
parent 69966519b0
commit 731d8cd9ff
13 changed files with 283 additions and 60 deletions

View File

@@ -27,32 +27,51 @@ def check_system_time():
print(f"Atlanta time: {atlanta_time}")
print(f"Timezone: {atlanta_time.tzname()}")
# Check against world time API
try:
print("\n🌐 Checking against world time API...")
response = requests.get("http://worldtimeapi.org/api/timezone/America/New_York", timeout=5)
if response.status_code == 200:
data = response.json()
api_time = datetime.datetime.fromisoformat(data['datetime'].replace('Z', '+00:00'))
# Compare times (allow 5 second difference)
time_diff = abs((atlanta_time.replace(tzinfo=None) - api_time.replace(tzinfo=None)).total_seconds())
print(f"API time: {api_time}")
print(f"Time difference: {time_diff:.2f} seconds")
if time_diff < 5:
print("✅ Time is synchronized (within 5 seconds)")
return True
# Check against multiple time APIs for reliability
time_apis = [
{
"name": "WorldTimeAPI",
"url": "http://worldtimeapi.org/api/timezone/America/New_York",
"parser": lambda data: datetime.datetime.fromisoformat(data['datetime'].replace('Z', '+00:00'))
},
{
"name": "WorldClockAPI",
"url": "http://worldclockapi.com/api/json/est/now",
"parser": lambda data: datetime.datetime.fromisoformat(data['currentDateTime'])
}
]
for api in time_apis:
try:
print(f"\n🌐 Checking against {api['name']}...")
response = requests.get(api['url'], timeout=5)
if response.status_code == 200:
data = response.json()
api_time = api['parser'](data)
# Compare times (allow 5 second difference)
time_diff = abs((atlanta_time.replace(tzinfo=None) - api_time.replace(tzinfo=None)).total_seconds())
print(f"API time: {api_time}")
print(f"Time difference: {time_diff:.2f} seconds")
if time_diff < 5:
print("✅ Time is synchronized (within 5 seconds)")
return True
else:
print("❌ Time is NOT synchronized (difference > 5 seconds)")
return False
else:
print("❌ Time is NOT synchronized (difference > 5 seconds)")
return False
else:
print("⚠️ Could not reach time API")
return None
except Exception as e:
print(f"⚠️ Error checking time API: {e}")
return None
print(f"⚠️ {api['name']} returned status {response.status_code}")
continue
except Exception as e:
print(f"⚠️ Error checking {api['name']}: {e}")
continue
print("⚠️ Could not reach any time API services")
print("⚠️ This may be due to network connectivity issues")
print("⚠️ System will continue but time synchronization cannot be verified")
return None
if __name__ == "__main__":
check_system_time()