24 lines
789 B
Python
24 lines
789 B
Python
import base64
|
|
import requests
|
|
from requests.auth import HTTPDigestAuth
|
|
import json
|
|
def getImage(res):
|
|
with open(f'./snapshot{res}.jpg', 'wb') as handle:
|
|
resp = requests.get(f"http://192.168.1.67:3067/cgi-bin/SnapshotJPEG?Resolution={res}", auth=HTTPDigestAuth("ASS", "amerus@1903"), stream=True)
|
|
for block in resp.iter_content(1024):
|
|
if not block:
|
|
break
|
|
|
|
handle.write(block)
|
|
with open(f'./snapshot{res}.jpg', 'rb') as img:
|
|
encoded_string = base64.b64encode(img.read())
|
|
|
|
return encoded_string.decode("UTF-8")
|
|
|
|
|
|
resolutions = ["640x360","1280x720", "1920x1080"]
|
|
for res in resolutions:
|
|
with open(f'./snapshot{res}.json', 'w') as f:
|
|
json.dump({"snapshot": getImage(res)}, f)
|
|
|
|
|