def all_isbns(): l = [] for k in redis.keys(): if k[0:4] == "rfid": continue try: [isbn, field] = k.split(":") l.append(isbn) except: continue return list(Set(l))
def collect_data(): if caches_defined(): global entries_cache, all_attributes_strings_cache return (entries_cache, all_attributes_strings_cache) entries = {} all_attributes_strings = [] for k in redis.keys(): a = redis.get(k) if k[0:4] == "rfid": continue try: [isbn, field] = k.split(":") try: entries[isbn][field] = a except: entries[isbn] = {} entries[isbn][field] = a if field == "author" or field == "book_title": all_attributes_strings.append(a) except: continue # reshape entry_list = [] for isbn in entries.keys(): field_dict = entries[isbn] field_dict['isbn'] = isbn entry_list.append(field_dict) # sort try: sorted_entry_list = sorted(entry_list, key=lambda dicty: dicty['book_title']) except: sorted_entry_list = [] entries_cache = sorted_entry_list all_attributes_strings_cache = json.dumps(all_attributes_strings).encode('utf8') return (entries_cache, all_attributes_strings_cache)