30 lines
834 B
Python
30 lines
834 B
Python
from flask import Flask, request, jsonify
|
|
import requests
|
|
import subprocess
|
|
import time
|
|
import logging
|
|
|
|
import config
|
|
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
|
|
|
|
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.')
|
|
|
|
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.')
|