import uuid class LocalDB: def __init__(self): self.users = {} self.categories = {} self.records = {} def reset(self): for k, v in list(self.users.items()): if v == "test1": del self.users[k] for k, v in list(self.categories.items()): if v == "test2": del self.categories[k] def get_users(self): return self.users def get_user(self, uid): if uid in self.users: return { 'uuid': uid, 'name': self.users[uid] } else: return {} def add_user(self, name): if not name: return {} if name in set(self.users.values()): return {} new_uuid = uuid.uuid4().hex self.users[new_uuid] = name return { 'uuid': new_uuid, 'name': name } def del_user(self, uid): if uid in self.users: name = self.users[uid] del self.users[uid] return { 'uuid': uid, 'name': name } else: return {} def get_category(self, uid): if uid in self.categories: return { 'uuid': uid, 'name': self.categories[uid] } else: return {} def add_category(self, name): if not name: return {} if name in set(self.categories.values()): return {} new_uuid = uuid.uuid4().hex self.categories[new_uuid] = name return { 'uuid': new_uuid, 'name': name } def del_category(self, uid): if uid in self.categories: name = self.categories[uid] del self.categories[uid] return { 'uuid': uid, 'name': name } else: return {}