forked from baardove/osc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPicture.py
36 lines (21 loc) · 883 Bytes
/
getPicture.py
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
#!/usr/bin/env python
import requests
import shutil
BASEURL = 'http://192.168.107.1/osc/'
data = {"name": "camera.listImages", "parameters": { "entryCount": 1} }
resp = requests.post(BASEURL + 'commands/execute', json=data)
if resp.status_code != 200:
# This means something went wrong.
raise ApiError('camera.listImages: {}'.format(resp.status_code))
name = (resp.json()["results"]["entries"][0]["name"])
uri = (resp.json()["results"]["entries"][0]["uri"])
data = {"name": "camera.getImage", "parameters": { "fileUri": uri} }
resp = requests.post(BASEURL + 'commands/execute', json=data)
if resp.status_code != 200:
# This means something went wrong.
raise ApiError('camera.getImage: {}'.format(resp))
resp.raw.decode_content = True
with open(name,'w') as ofh:
for chunk in resp:
ofh.write(chunk)
print ('Image: {}'.format(name))