grabSnapshot.py example
This commit is contained in:
BIN
test/files/20260606_140132_cam0_front.jpg
Normal file
BIN
test/files/20260606_140132_cam0_front.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
BIN
test/files/20260606_140335_cam0_front.jpg
Normal file
BIN
test/files/20260606_140335_cam0_front.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
BIN
test/files/20260606_140335_cam1_left.jpg
Normal file
BIN
test/files/20260606_140335_cam1_left.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
BIN
test/files/20260606_140335_cam2_right.jpg
Normal file
BIN
test/files/20260606_140335_cam2_right.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 272 KiB |
48
test/grabSnapShot.py
Normal file
48
test/grabSnapShot.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import requests
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
BASE_URL = "http://thinkcentre.local:8444"
|
||||||
|
|
||||||
|
def snapshot_all_hires(out_dir: str = "."):
|
||||||
|
out = Path(out_dir)
|
||||||
|
out.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
cameras = requests.get(f"{BASE_URL}/api/cameras", timeout=5).json()["cameras"]
|
||||||
|
|
||||||
|
results = {}
|
||||||
|
errors = {}
|
||||||
|
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
|
||||||
|
for cam in cameras:
|
||||||
|
cam_id = cam["id"]
|
||||||
|
url = f"{BASE_URL}/api/snapshot/{cam_id}/hires"
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = requests.get(url, timeout=20)
|
||||||
|
if not resp.ok:
|
||||||
|
reason = resp.json().get("error", resp.text) if resp.content else resp.reason
|
||||||
|
print(f"{cam_id} ({cam['name']}): FEHLER {resp.status_code} – {reason}")
|
||||||
|
errors[cam_id] = reason
|
||||||
|
continue
|
||||||
|
|
||||||
|
filename = out / f"{ts}_{cam_id}_{cam['position']}.jpg"
|
||||||
|
filename.write_bytes(resp.content)
|
||||||
|
w = resp.headers.get("X-Frame-Width", "?")
|
||||||
|
print(f"{cam_id} ({cam['name']}): {len(resp.content)//1024} kB, {w}px → {filename.name}")
|
||||||
|
results[cam_id] = str(filename)
|
||||||
|
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
print(f"{cam_id} ({cam['name']}): TIMEOUT (>20s)")
|
||||||
|
errors[cam_id] = "timeout"
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{cam_id} ({cam['name']}): EXCEPTION – {e}")
|
||||||
|
errors[cam_id] = str(e)
|
||||||
|
|
||||||
|
return results, errors
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
files, errs = snapshot_all_hires("./files")
|
||||||
|
print("\nErfolg:", files)
|
||||||
|
if errs:
|
||||||
|
print("Fehler:", errs)
|
||||||
Reference in New Issue
Block a user