From 9852f162d4962065d6d4ab8a8e7c513b315b4fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Enrique=20G=C3=B3mez=20G=C3=B3mez?= Date: Thu, 12 Jan 2023 19:18:29 +0000 Subject: [PATCH] main[ADD]attendance_flask:Codigos QR para asistencias --- get_query.py | 35 ++++++++++++++++++++--------------- main.py | 7 ++++--- schema.sql | 3 ++- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/get_query.py b/get_query.py index 6f8e063..6c76385 100644 --- a/get_query.py +++ b/get_query.py @@ -10,20 +10,25 @@ def get_db_connection(): return conn conn = get_db_connection() -data = conn.execute('SELECT user, datein, dateout, ip_branch, id FROM hits WHERE dateout != ? AND dateinspe = ? ', ('', '')).fetchall() +data = conn.execute('SELECT user, datein, dateout, ip_branch, id, inspein, inspeout FROM hits WHERE datein != ? AND inspein = ? OR dateout != ? AND inspeout = ? ', ('', '', '', '')).fetchall() for d in data: - params ={ - 'access': 'YXR0ZW5kYW5jZXMvYWdvZmVy', - 'employee_id': d[0], - 'check_in': d[1], - 'check_out': d[2], - 'ip_branch': d[3], - } - response = requests.post('http://137.184.126.24:8080/hr_attendance_extended/public/attendance/', json = params).json() - if response["message"]: - time = datetime.now(pytz.timezone('America/Bogota')).strftime("%Y-%m-%d %H:%M:%S") - conn.execute("UPDATE hits SET dateinspe = ? WHERE id = ?", (time, d[4])) - conn.commit() - else: - continue + params ={ + 'access': 'YXR0ZW5kYW5jZXMvYWdvZmVy', + 'employee_id': d[0], + 'check_in': d[1], + 'check_out': d[2], + 'ip_branch': d[3], + } + response = requests.post('https://erp.agofer.com/hr_attendance_extended/public/attendance/', json = params).json() + print(response) + if response["message"]: + time = datetime.now(pytz.timezone('America/Bogota')).strftime("%Y-%m-%d %H:%M:%S") + if d[1] != '' and d[5] == '': + conn.execute("UPDATE hits SET inspein = ? WHERE id = ?", (time, d[4])) + if d[2] != '' and d[6] == '': + conn.execute("UPDATE hits SET inspeout = ? WHERE id = ?", (time, d[4])) + conn.commit() + else: + continue + diff --git a/main.py b/main.py index 85f9dd7..e8f582d 100755 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ import requests app = Flask(__name__) + FlaskUUID(app) qrcode = QRcode(app) app.config['SECRET_KEY'] = '53a8373e7ae652cd38beba15454b1dc4' @@ -66,8 +67,7 @@ def generate_next_url(type, ip_branch): @app.route('/') def show_qr_and_list(): # TODO: reject direct connections to server; allow access only via proxy - get_list = requests.get( - 'http://137.184.126.24:8080/hr_attendance_extended/public/attendance/').json() + get_list = requests.get('https://erp.agofer.com/hr_attendance_extended/public/attendance/').json() list_ips = get_list["list_ips"] ip_branch = request.environ.get('HTTP_X_REAL_IP', request.remote_addr) if ip_branch in list_ips: @@ -110,10 +110,11 @@ def catch_uuids(id, hashed, type, ip_branch): error = 'MISSING_EXIT' else: conn.execute( - "INSERT INTO hits (user, uuid1, datein) VALUES (?, ?, ?)", (user, str(id), time)) + "INSERT INTO hits (user, uuid1, datein, ip_branch) VALUES (?, ?, ?, ?)", (user, str(id), time, str(ip_branch))) conn.commit() url = generate_next_url(type_check, str(ip_branch)) qr = qrcode(url) + os.system('python get_query.py') socketio.emit('qr_used', {'data': ( qr, url, user, time, type_check,)}) elif type_check == 'CheckOut': diff --git a/schema.sql b/schema.sql index 5171122..7a7f54f 100644 --- a/schema.sql +++ b/schema.sql @@ -8,6 +8,7 @@ CREATE TABLE hits ( datein TEXT NOT NULL DEFAULT '' , dateout TEXT NOT NULL DEFAULT '', ip_branch TEXT NOT NULL DEFAULT '', - dateinspe TEXT NOT NULL DEFAULT '' + inspein TEXT NOT NULL DEFAULT '', + inspeout TEXT NOT NULL DEFAULT '' );