def load(self): "return a dictionary of dictionaries with member info indexed by hashed rfid" try: f = open(self.filename) lines = f.read().splitlines() f.close() except: botlog.critical("authenticate can't read CSV %s" % self.filename) return {} cd = {} for l in lines[1:]: try: (member, value, key, allowed, tagid, lastAccessed) = [x[1] for x in self.csv_regexp.findall(l)] cd[tagid] = { 'member': member, 'allowed': allowed, 'tagid': tagid, 'warning': None, 'plan': None, 'nickname': None } except: botlog.error('authenticate CSV fail: %s %s' % (l, sys.exc_info())) botlog.info("authenticate read CSV %s %d entries" % (self.filename, len(cd))) return cd
def reload(self) : "check the file and reload data if needed" try: fd = os.open(self.filename, os.O_RDONLY) fi = os.fstat(fd) os.close(fd) if fi.st_mtime > self.file_time : self.card_data = self.load() self.file_time = fi.st_mtime except OSError as e: botlog.critical( "reload exception on file %s: %s" % (self.filename, e.strerror)) except: botlog.critical( "reload exception on file %s: %s" % (self.filename, sys.exc_info()))
def reload(self): "check the file and reload data if needed" try: fd = os.open(self.filename, os.O_RDONLY) fi = os.fstat(fd) os.close(fd) if fi.st_mtime > self.file_time: self.card_data = self.load() self.file_time = fi.st_mtime except OSError as e: botlog.critical("reload exception on file %s: %s" % (self.filename, e.strerror)) except: botlog.critical("reload exception on file %s: %s" % (self.filename, sys.exc_info()))
def load(self): "return a dictionary of dictionaries with member info indexed by hashed rfid" try: f = open(self.filename) lines = f.read().splitlines() f.close() except: botlog.critical( "authenticate can't read CSV %s" % self.filename) return {} cd = {} for l in lines[1:] : try : (member,value,key,allowed,tagid,lastAccessed) = [x[1] for x in self.csv_regexp.findall(l)] cd[tagid] = {'member': member, 'allowed': allowed, 'tagid':tagid, 'warning':None, 'plan':None, 'nickname':None} except: botlog.error( 'authenticate CSV fail: %s %s' % (l, sys.exc_info())) botlog.info( "authenticate read CSV %s %d entries" % (self.filename, len(cd))) return cd