grabSnapshot.py example

This commit is contained in:
chk
2026-06-06 14:08:35 +02:00
parent 92b17b18be
commit bfe47d5410
5 changed files with 48 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

48
test/grabSnapShot.py Normal file
View 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)