50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
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]
|
|
|
|
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 {}
|