I have then made a Mysql database where I am storing the punches.
So now, I am thinking it would be better to pull the initial scan from the mysql database as well and get rid of the csv file. I do not understand how the dictionary code is written, so am unable to accomplish this. I am able to connect to the DB w/o issue. Here is my current code using the dictionary. Where it currently says #Do Something, is where I am currently connecting to my DB, and recording the punches. So I will need to connect to the DB at first launch and read the values from my table into the dictionary instead of the csv file values..
Code: Select all
import MFRC522
import signal
import datetime
import time
import os
import sys
import RPi.GPIO as GPIO
import csv
import MySQLdb
from time import sleep
from Adafruit_CharLCD import Adafruit_CharLCD
# VARIABLES
uid_dict = dict()
uid_file = "/mnt/lock_logs/timeclock.csv"
fieldnames = ['UUID', 'USERS']
# UID DICTIONARY
with open(uid_file, "r") as f:
reader = csv.DictReader(f, fieldnames=fieldnames, delimiter=",")
for row in reader:
uid_dict[row['USERS'].strip()] = [int(i) for i in row['UUID'].split()]
while continue_reading:
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
(status,backData) = MIFAREReader.MFRC522_Anticoll()
for key, value in uid_dict.iteritems():
if backData == value:
#Do Something