import sqlite3 from datetime import datetime import pytz import requests def get_db_connection(): conn = sqlite3.connect('database.db') conn.row_factory = sqlite3.Row return conn conn = get_db_connection() 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('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