48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
|
#!/usr/bin/python
|
||
|
import threading
|
||
|
import requests
|
||
|
import datetime
|
||
|
import time
|
||
|
import os
|
||
|
import sys
|
||
|
|
||
|
delay = 10.0
|
||
|
resolution = "1280x960"
|
||
|
localDir = './photos/'
|
||
|
|
||
|
if sys.argv[1]:
|
||
|
localDir = sys.argv[1] +"/"
|
||
|
|
||
|
if sys.argv[2]:
|
||
|
delay = float(sys.argv[2])
|
||
|
|
||
|
# Change here with your IP
|
||
|
url = 'http://poi:poi@192.168.0.32:8888/photo.jpg'
|
||
|
focusUrl = 'http://poi:poi@192.168.0.32:8888/focus'
|
||
|
|
||
|
def convpicture(infile, outfile,resolution):
|
||
|
quali = 80
|
||
|
command = 'convert {} -quality {} -resize {} {}'.format(infile,quali,resolution,outfile)
|
||
|
os.system(command)
|
||
|
|
||
|
def takePicture():
|
||
|
# focus did better with macro picture
|
||
|
Focus_request = requests.get(focusUrl)
|
||
|
if Focus_request.status_code == 200:
|
||
|
time.sleep(1) # important
|
||
|
Img_request = requests.get(url)
|
||
|
if Img_request.status_code == 200:
|
||
|
time.sleep(1)
|
||
|
now = datetime.datetime.now()
|
||
|
name = now.strftime('%Y%m%d_%H%M%S' ) +'.jpg'
|
||
|
print ('get picture '+ name)
|
||
|
with open( localDir + 'last.jpg', 'wb') as f:
|
||
|
f.write(Img_request.content)
|
||
|
convpicture(localDir+'last.jpg',localDir+ name,resolution)
|
||
|
|
||
|
def printit():
|
||
|
threading.Timer(delay, printit).start()
|
||
|
takePicture()
|
||
|
|
||
|
printit()
|