You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

45 lines
1000 B

from flask import (
Blueprint, flash, g, redirect, render_template, request, url_for
)
from werkzeug.exceptions import abort
from app.auth import login_required
from app.db import get_db
# import RPi.GPIO as GPIO
bp = Blueprint('lights', __name__)
@bp.route('/')
def index():
db = get_db()
status = db.execute(
'SELECT user_id, status, created'
' FROM status JOIN user ON status.user_id = user.id'
' ORDER BY created DESC LIMIT 1'
).fetchone()
return render_template('lights/index.html.j2', status=status)
@bp.route('/toggle')
@login_required
def toggle():
db = get_db()
status = db.execute(
'SELECT status'
' FROM status JOIN user ON status.user_id = user.id'
' ORDER BY created DESC LIMIT 1'
).fetchone()
# if status['status']:
# GPIO.output(17, GPIO.LOW)
# else:
# GPIO.output(17, GPIO.HIGH)
db.execute(
'INSERT INTO status (user_id, status)'
' VALUES (?, ?)',
(g.user['id'], not status['status'])
)
db.commit()
return redirect(url_for('lights.index'))