ich versuche mich gerade an einem Raspberry Pi RFID Zeiterfassungstool.
Code: Alles auswählen
#!/usr/bin/env python
import time
from contextlib import closing
import drivers
import mysql.connector
from mfrc522 import SimpleMFRC522
from RPi import GPIO
def main():
try:
with closing(
mysql.connector.connect(
host="localhost",
user="***",
passwd="***",
database="attendancesystem",
)
) as db:
with db.cursor() as cursor:
reader = SimpleMFRC522()
lcd = drivers.Lcd()
try:
while True:
lcd.lcd_clear()
lcd.lcd_display_string("Place Card to", 1)
lcd.lcd_display_string("record attendance", 2)
rfid, _ = reader.read()
search_rfid_sql = "SELECT * FROM users JOIN attendance ON user_id = in_or_out = 1 and rfid_uid = %s"
cursor.execute(search_rfid_sql,[rfid],)
result = cursor.fetchone()
lcd.lcd_clear()
if result:
user_id,username,in_or_out = result
if in_or_out == 1:
print("du bist schon angemeldet")
else:
lcd.lcd_display_string(f"Welcome {username}.", 1)
insert_coming_sql = "INSERT INTO attendance (user_id, in_or_out) VALUES (%s, 1);"
cursor.execute(insert_coming_sql, (user_id,))
db.commit()
else:
lcd.lcd_display_string("User does not exist.", 1)
time.sleep(2)
finally:
lcd.lcd_clear()
finally:
GPIO.cleanup()
if __name__ == "__main__":
main()
und ich habe keine Ahnung wie ich das umgehen kann, dafür bin ich noch zu blutiger Anfänger und kapiere es einfach nicht.ValueError: too many values to unpack (expected 3)
meine DB sieht so aus:
Code: Alles auswählen
MariaDB [attendancesystem]> DESCRIBE attendance;
+-----------+------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(10) unsigned | NO | | NULL | |
| clock_in | timestamp | NO | | current_timestamp() | |
| in_or_out | tinyint(1) | YES | | 0 | |
| clock_out | date | YES | | NULL | |
+-----------+------------------+------+-----+---------------------+----------------+
5 rows in set (0,011 sec)
MariaDB [attendancesystem]> DESCRIBE users;
+----------+-----------------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-----------------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| rfid_uid | varchar(255) | NO | | NULL | |
| name | varchar(255) | NO | | NULL | |
| created | timestamp /* mariadb-5.3 */ | NO | | current_timestamp() | |
+----------+-----------------------------+------+-----+---------------------+----------------+
4 rows in set (0,010 sec)
Danke schon mal
Gruß
Susie