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 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
door_hw.open_sesame() else: #2 # access failed. blink the red # botlog.warning('%s DENIED' % username) door_hw.blink_red() else: #5 botlog.warning('Unknown card %s ' % rfid_str) door_hw.blink_red() except: #4 # bad input catcher, also includes bad cards # botlog.warning('bad card %s ' % rfid_str) door_hw.blink_red(4) except: e = traceback.format_exc().splitlines()[-1] botlog.error('door loop unexpected exception: %s' % e) pass sleep(3) reader.flush() # needed for serial reader that keeps sending stuff. # 0001258648
#2 # access failed. blink the red # botlog.warning('%s DENIED' % username) door_hw.blink_red() else : #5 botlog.warning('Unknown card %s ' % rfid_str) door_hw.blink_red() except : #4 # bad input catcher, also includes bad cards # botlog.warning('bad card %s ' % rfid_str) door_hw.blink_red(4) except : e = traceback.format_exc().splitlines()[-1] botlog.error('door loop unexpected exception: %s' % e) pass sleep(3) reader.flush() # needed for serial reader that keeps sending stuff. # 0001258648