Ejemplo n.º 1
0
def takePicApi():

    if request.headers['Content-Type'] == 'application/json':
        try:
            request.json['picQuality']
        except:
            return "json message not accepted"

        rootDir = os.path.dirname(os.path.abspath(__file__))
        fileName = 'picam_ondemand_'+ datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') + '.jpg'
        fileName = os.path.join(rootDir, 'static/', fileName)
        
        if request.json['picQuality'] == 'low':
            takePicture(fileName, 'low')
        else:
            takePicture(fileName, 'high')

        urlImg = url_for('static', filename=os.path.basename(fileName))
        js = json.dumps({'urlImg':urlImg})
        
        resp = Response(js, status=200, mimetype='application/json')
        resp.headers['Link'] = 'http://luisrei.com'
        return resp
    else:
        return "415 Unsupported Media Type ;)"
Ejemplo n.º 2
0
def load():
    rootDir = os.path.dirname(os.path.abspath(__file__))
    fileName = 'picam_ondemand_'+ datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') + '.jpg'
    fileName = os.path.join(rootDir, 'static/', fileName)

    takePicture(fileName, 'low')

    urlImg = url_for('static', filename=os.path.basename(fileName))

    response =  'Take shots for the monitoring environment.'
    templateData = {
        'title' : 'Pi monitoring',
        'response': response,
        'urlImg': urlImg,
        'urlList': url_for('list'),
        }
    return render_template('load.html', **templateData)