main[ADD]attendance_flask:Codigos QR para asistencias
This commit is contained in:
parent
65bc6d61e8
commit
9852f162d4
35
get_query.py
35
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
|
||||
|
||||
|
||||
7
main.py
7
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':
|
||||
|
||||
@ -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 ''
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user