From 52422f1e6c13d65a4902fbbd50f4e5bb0f5c5813 Mon Sep 17 00:00:00 2001 From: pjrepl5ha <2714394835@qq.com> Date: Fri, 31 May 2024 20:12:55 +0800 Subject: [PATCH] ADD file via upload --- db.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 db.py diff --git a/db.py b/db.py new file mode 100644 index 0000000..aa6dd76 --- /dev/null +++ b/db.py @@ -0,0 +1,55 @@ +import json + + +class MysqlDatabases: + def __init__(self): + self.users = json.loads(open('users.json', mode='r', encoding='utf-8').read()) + self.bkuser = json.loads(open('bkuser.json', mode='r', encoding='utf-8').read()) + + def check_login(self, username, password): + for user in self.users: + if username == user['username']: + if password == user['password']: + return True, '登录成功' + else: + return False, '登录失败,密码不存在' + return False, '登录失败,用户不存在' + + def all(self): + return self.bkuser + + def insert(self, bk): + self.bkuser.append(bk) + + def delete_by_username(self, name): + for bk in self.bkuser: + print(bk) + if bk['name'] == name: + self.bkuser.remove(bk) + return True, f'{name}删除用户成功' + return False, f'{name}用户不存在' + + def search_by_username(self, name): + for bk in self.bkuser: + print(bk) + if bk['name'] == name: + return True, bk + return False, f'{name}用户不存在' + + def update(self, bk1): + for bk in self.bkuser: + if bk['name'] == bk1['name']: + bk.update(bk1) + return True, f'{bk1["name"]}用户修改数据成功' + return False, f'{bk1["name"]}用户不存在' + + def register(self,user1): + pass + + +db = MysqlDatabases() + +if __name__ == '__main__': + # print(db.check_login('admin','123456')) + # print(db.all()) + print(db.search_by_username('张三')) \ No newline at end of file