This commit is contained in:
2000-Trek 2023-05-31 22:29:47 +02:00
parent 3df799a491
commit 69cd99d3e3
2 changed files with 17 additions and 11 deletions

16
main.py
View file

@ -1,5 +1,5 @@
import queue
from flask import Flask, render_template, request, make_response
from flask import Flask, render_template, request, make_response, flash
from flask_socketio import SocketIO #https://pythonprogramminglanguage.com/python-flask-websocket/
import sqlite3
import time
@ -37,7 +37,7 @@ def list():
return '<form action="/list/user" method="get"> Search for User: <input name="user"><input type="submit"></form> <form action="/adduser" method="get"><button type="submit">Add User</button></form> <br></br>' + text
@app.route("/list/user", methods=['GET'])
def user():
def user_info():
username = request.args.get("user")
c.execute("SELECT * FROM users WHERE username = '%s'" % username)
user = c.fetchall()
@ -89,23 +89,31 @@ def get_addtag_request():
except: #except im Normalen Code!
return "Wrong user id!"
users.put(user_id)
print(f"put: {len(users.queue)}")
return render_template("addtag.html", user=user_id)
@socketio.on('addtag')
def request_addtag(data):
global finished
print(f"add tag: {len(users.queue)}")
if len(users.queue) > 0:
user = users.queue[len(users.queue) - 1]
if user == data["data"]:
socketio.emit("wait", "wait")
i = 0
while finished != data["data"]:
print("waiting")
time.sleep(1)
i += 1
if i > 20:
print("timeout")
socketio.emit("error", "timeout")
nothing = users.get()
pass
print(f"nothing: {nothing}")
print("cleared")
break
else:
finished = None
c.execute(f"SELECT * FROM users WHERE id ={user}")
username = c.fetchall()[0][1]
c.execute(f"SELECT * FROM tags WHERE userid={user}")
@ -119,7 +127,6 @@ def request_addtag(data):
#api
@app.route("/api/tag_id", methods=['GET'])
def get_id():
global users
global finished
tag_id = int(request.args.get("id"))
c.execute(f"SELECT * FROM tags WHERE tagid ={tag_id}")
@ -143,4 +150,3 @@ def get_id():
def main():
atexit.register(exit_handler)
socketio.run(app, host='0.0.0.0', port=5000)

View file

@ -12,7 +12,7 @@
socket.emit('addtag', {data: user})
});
socket.on("wait", function(){
document.write('<p>wait</p>')
document.write('<p>Pleas hold your tag on to the nfc reader</p>')
});
socket.on("error", function(data) {
alert(data)