-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate_time_sync.py
More file actions
54 lines (47 loc) · 2.05 KB
/
date_time_sync.py
File metadata and controls
54 lines (47 loc) · 2.05 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (c) 2024 Andrii Shramko
# Contact: zmei116@gmail.com
# LinkedIn: https://www.linkedin.com/in/andrii-shramko/
# Tags: #ShramkoVR #ShramkoCamera #ShramkoSoft
# License: This code is free to use for non-commercial projects.
# For commercial use, please contact Andrii Shramko at the above email or LinkedIn.
import requests
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor
from goprolist_and_start_usb import discover_gopro_devices
# Function to synchronize time on all discovered cameras
def sync_time_on_cameras():
# Discover connected cameras
devices = discover_gopro_devices()
if not devices:
print("No GoPro devices found.")
return
# Get the list of IP addresses for all discovered cameras
camera_ips = [device["ip"] for device in devices]
# Get the current system time
current_time = datetime.now()
date = current_time.strftime("%Y_%m_%d") # Format current date as YYYY_MM_DD
time = current_time.strftime("%H_%M_%S") # Format current time as HH_MM_SS
timezone_offset = int(current_time.utcoffset().total_seconds() / 60) if current_time.utcoffset() else 0
dst = 1 if current_time.dst() else 0
# Function to synchronize time on a single camera
def sync_camera_time(ip):
url = f"http://{ip}:8080/gopro/camera/set_date_time"
params = {
"date": date,
"time": time,
"tzone": timezone_offset,
"dst": dst
}
try:
response = requests.get(url, params=params)
if response.status_code == 200:
print(f"Time synchronization successful on camera {ip}.")
else:
print(f"Failed to synchronize time on camera {ip}: {response.status_code}")
except requests.RequestException as e:
print(f"Error connecting to camera {ip}: {e}")
# Synchronize time on all cameras concurrently
with ThreadPoolExecutor() as executor:
executor.map(sync_camera_time, camera_ips)
if __name__ == "__main__":
sync_time_on_cameras()