copy from URL snapshot to a local file

Posted on
Sun Dec 02, 2018 11:37 am
johnpolasek offline
Posts: 911
Joined: Aug 05, 2011
Location: Aggieland, Texas

copy from URL snapshot to a local file

In applescript, I used
Code: Select all
do shell script "curl -f 'http://192.168.11.xxx:7080/api/2.0/snapshot/camera/yyyyyyyyyyyyyyyy?force=true&apiKey=zzzzzzzzzz -o ~/Documents/DrivewayFolder/Driveway0.jpg"


but in python, neither requests get, put, or post will do it. Do I need to do a get into an indigo variable and then an os call to put into the file?

Posted on
Tue Dec 04, 2018 11:20 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: copy from URL snapshot to a local file

So, curl is doing 2 things for you here: it's downloading the image data, then it's storing it in the specified file. In Python, this would be two steps: have requests download the data, then write the data to a file:

Code: Select all
import requests

url = 'http://192.168.11.xxx:7080/api/2.0/snapshot/camera/yyyyyyyyyyyyyyyy?force=true&apiKey=zzzzzzzzzz'

# Make the request and get the reply
reply = requests.get(url)

# This will raise an exception if the request returned an error
reply.raise_for_status()

# Save the content to a file
with open('/full/path/to/Documents/DrivewayFolder/Driveway0.jpg', 'wb') as image_file:
    image_file.write(reply.content)


Untested but it should be close.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Dec 04, 2018 11:25 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: copy from URL snapshot to a local file

Code: Select all
import os
os.system("/usr/bin/curl -f 'http://192.168.11.xxx:7080/api/2.0/snapshot/camera/yyyyyyyyyyyyyyyy?force=true&apiKey=zzzzzzzzzz -o ~/Documents/DrivewayFolder/Driveway0.jpg")
should do it

Karl

if you want to get fancy with the parameters:
Code: Select all
import os
apiKey = indigo.variables["variable name where you store the api key"].value
os.system("/usr/bin/curl -f 'http://192.168.11.xxx:7080/api/2.0/snapshot/camera/yyyyyyyyyyyyyyyy?force=true&apiKey='"+apiKey+"' -o ~/Documents/DrivewayFolder/Driveway0.jpg")

and you can do the same for ip number .. camera # ..
{EDIT] Jay's post happened at the same time .. several ways .. mine is for an action, but can also be used in std python

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests