-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
67 lines (45 loc) · 1.66 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#Master Database file for Users
import os
from deta import Deta
from dotenv import load_dotenv
import uuid
load_dotenv(".env")
DETA_KEY = os.getenv("DETA_KEY")
deta = Deta(DETA_KEY)
db = deta.Base("Users")
def generate_unique_user_id():
return str(uuid.uuid4())
def create_id(username):
#user=db.get(username)
user_id = generate_unique_user_id()
#return db.put({"key":username,"user_id": user_id})
return db.update({"user_id": user_id}, username)
def insert_user(username, name, password, email, profile):
user_id = generate_unique_user_id() # Generate a unique user ID
return db.put({"key": username, "user_id": user_id, "name": name, "password": password, "email": email, "profile": profile})
def fetch_all_users():
res=db.fetch()
return res.items
def get_user_id(username):
user = db.get(username)
return user["user_id"] if user else None
def get_user_fullname(username):
user = db.get(username)
return user["name"] if user else None
def get_user(username):
return db.get(username)
def get_user_by_email(email):
res = db.fetch({"email": email})
return res.items[0] if res.count > 0 else None
def update_user_password(username, new_password):
return db.update({"password": new_password}, username)
#insert_user ("pparker", "Peter Parker" , "abc123" )
#print(get_user("nnarra"))
def update_all_users_with_id():
users = fetch_all_users()
for user in users:
if 'user_id' not in user:
create_id(user["key"])
#update_all_users_with_id()
#print(get_user_id("nnarra"))
#print(get_user_fullname("nnarra"))