Skip to content

Instantly share code, notes, and snippets.

@sarful
Last active May 30, 2020 10:00
Show Gist options
  • Save sarful/3e015f5f7d194ffc8a2186aed3ad9ce1 to your computer and use it in GitHub Desktop.
Save sarful/3e015f5f7d194ffc8a2186aed3ad9ce1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import time
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="username",
passwd="your_password",
database="attendance_system"
)
cursor = db.cursor()
reader = SimpleMFRC522()
try:
while True:
print('Place Card to\nrecord attendance')
id, text = reader.read()
cursor.execute("Select id, name FROM users WHERE rfid_uid="+str(id))
result = cursor.fetchone()
if cursor.rowcount >= 1:
print("Welcome " + result[1])
cursor.execute("INSERT INTO attendance (user_id) VALUES (%s)", (result[0],) )
db.commit()
else:
print("User does not exist.")
time.sleep(2)
finally:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment