-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminPanel.py
60 lines (53 loc) · 1.91 KB
/
adminPanel.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
import pyrebase, json
from conf import login
class admin:
def __init__(self):
firebase = pyrebase.initialize_app(login.CONFIG)
self.auth = firebase.auth()
self.db = firebase.database()
self.ex = False
def login(self, email, passwd):
try:
self.auth.sign_in_with_email_and_password(email, passwd)
self.ex = True
except Exception as e:
self.ex = json.loads(e.args[1])['error']['message']
finally:
return self.ex
def add_new(self, email, passwd):
try:
user = self.auth.create_user_with_email_and_password(email, passwd)
self.auth.send_email_verification(user['idToken'])
self.ex = True
except Exception:
self.ex = False
finally:
return self.ex
def get_log(self):
data = self.db.child('log').get().val()
new_data = []
for date in data:
for time in data[date]:
dic = {
'admin': data[date][time]['admin'],
'semester': data[date][time]['semester'],
'session': data[date][time]['session'],
'year': data[date][time]['year'],
'date': '{} ({})'.format(date, time),
}
new_data.append(dic)
return new_data
def post_log(self, data):
import datetime
dt = datetime.datetime.now()
self.db.child('log').child(dt.date()).child(str(dt.hour)+':'+str(dt.minute)+':'+str(dt.second)).set(data)
def get_last_result(self):
data = self.db.child('log').get().val()
li, ti = [], []
for date in data:
for time in data[date]:
li.append(date)
for time in data[sorted(li)[-1]]:
ti.append(time)
d = data[sorted(li)[-1]][sorted(ti)[-1]]
return d['semester'], d['year']