-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_func.py
72 lines (56 loc) · 2.38 KB
/
db_func.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
68
69
70
71
72
from db import User, System, Message
def get_user(username):
user = User.query.filter_by(username=username).first()
return user
def verify_user(username,password):
this_user = User.query.filter_by(username=username).first()
if this_user != None:
return password == this_user.password
return False
def get_sys_name(username):
this_user = User.query.filter_by(username=username).first()
return this_user.sysname
def get_message(message_id):
return Message.query.filter_by(id=message_id).first()
def get_messages(username):
messages = Message.query.filter_by(username=username,archived=False).order_by(Message.id.desc()).all()
return [message.id for message in messages]
def get_archived_messages(username):
messages = Message.query.filter_by(username=username,archived=True).order_by(Message.id.desc()).all()
return [message.id for message in messages]
def get_messages_from(username,alter_id):
messages = Message.query.filter_by(username=username,alter_id=alter_id).all()
return [message.id for message in messages]
def get_alter(alter_id):
return System.query.filter_by(id=alter_id).first()
def get_alter_id(username,alter_name):
this = System.query.filter_by(username=username,alter=alter_name).first()
return this.id
def get_alter_name(alter_id):
alter = System.query.filter_by(id=alter_id).first()
return alter.alter
def get_alter_color(alter_id):
alter = System.query.filter_by(id=alter_id).first()
return alter.color
def get_alters(username):
sys = System.query.filter_by(username=username).order_by(System.alter.asc()).all()
return [i.id for i in sys]
def is_archived(message_id):
message = Message.query.filter_by(id=message_id).first()
return message.archived
def set_user(username,password,sysname):
return User(username=username, password=password, sysname=sysname)
def set_alter(username,alter):
high = System.query.order_by(System.id.desc()).first()
if high == None:
next = 0
else:
next = high.id + 1
return System(id=next,username=username, alter=alter, color="#000000")
def set_message(username,alter_id,message,now):
high = Message.query.order_by(Message.id.desc()).first()
if high == None:
next = 0
else:
next = high.id + 1
return Message(id=next,username=username, alter_id=alter_id, message=message, archived=False, datetime=now)