hyttekamera/camera/upload_img.py

30 lines
834 B
Python
Raw Normal View History

2022-01-18 15:34:10 +00:00
from flask import Flask, request, jsonify
import requests
2022-01-19 18:01:20 +00:00
import subprocess
import time
import logging
2022-01-18 15:34:10 +00:00
2022-01-19 18:01:20 +00:00
import config
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
2022-01-18 15:34:10 +00:00
2022-01-19 18:01:20 +00:00
try:
start = time.time()
picturecmd=subprocess.Popen("termux-camera-photo -c 0 latest.jpg", shell=True)
picturecmd.communicate()
end = time.time()
except Exception as e:
logging.info('Feil under fotografering: {0}'.format(e))
else:
logging.info('Det tok '+ str(end-start) +'s å ta bilde.')
2022-01-18 15:34:10 +00:00
2022-01-19 18:01:20 +00:00
try:
start = time.time()
img = {'image': open('latest.jpg', 'rb')}
response = requests.post(config.config['uploadurl'], files=img)
end = time.time()
except Exception as e:
logging.info('Feil under opplasting: {0}'.format(e))
else:
print(response.json())
logging.info('Det tok '+ str(end-start) +'s å sende bildet.')