def read_card_data(csv_filename):
    "return a dictionary of (username,key,allowed) indexed by hashed rfid"

    try:
        f = open(csv_filename)
        lines = f.read().splitlines()
        f.close()
    except:
        botlog.critical("authenticate can't read CSV %s" % csv_filename)
        return {}

    cd = {}
    for l in lines[1:]:
        try:
            (username, value, key, allowed, hashedCard,
             lastAccessed) = [x[1] for x in csv_line.findall(l)]
            # throw away value(?) and lastAccessed
            cd[hashedCard] = (username, allowed)

        except:
            botlog.error('authenticate CSV fail: %s' % l)

    botlog.info("authenticate read CSV %s %d entries" %
                (csv_filename, len(cd)))
    return cd
def re_read_file(csv_filename=card_data_file):
    "check the file and reload data if needed"

    global card_data
    global file_time

    try:
        fd = os.open(csv_filename, os.O_RDONLY)
        fi = os.fstat(fd)
        os.close(fd)

        if fi.st_mtime > file_time:
            card_data = read_card_data(csv_filename)
            file_time = fi.st_mtime
    except:
        botlog.critical("authenticate can't fstat CSV %s" % csv_filename)
Пример #3
0
def re_read_file(csv_filename=card_data_file) :
    "check the file and reload data if needed"

    global card_data
    global file_time


    try :
        fd = os.open(csv_filename,os.O_RDONLY)
        fi = os.fstat(fd)
        os.close(fd)

        if fi.st_mtime > file_time :
            card_data = read_card_data(csv_filename)
            file_time = fi.st_mtime
    except :
        botlog.critical( "authenticate can't fstat CSV %s" % csv_filename)
Пример #4
0
def read_card_data(csv_filename) :
    "return a dictionary of (username,key,allowed) indexed by hashed rfid"

    try :
        f = open(csv_filename)
        lines = f.read().splitlines()
        f.close()
    except :
        botlog.critical( "authenticate can't read CSV %s" % csv_filename)
        return {}
    
    cd = {}
    for l in lines[1:] :
        try :
            (username,value,key,allowed,hashedCard,lastAccessed) = [x[1] for x in csv_line.findall(l)]
            # throw away value(?) and lastAccessed
            cd[hashedCard] = (username,allowed)

        except :
            botlog.error( 'authenticate CSV fail: %s' % l)

    botlog.info( "authenticate read CSV %s %d entries" % (csv_filename, len(cd)))
    return cd