-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.py
39 lines (31 loc) · 966 Bytes
/
session.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
import json
import time
# fetch the UsersSession file
def fetchUsersSession():
jsonFile = open('./JSON/usersSession.json', 'r')
jsonData = json.load(jsonFile)
jsonFile.close()
return jsonData
# save the changes we did on the UsersSession file
def saveUsersSession(jsonData):
f = open('./JSON/usersSession.json', 'w')
newJson = json.dumps(jsonData)
f.write(newJson)
f.close()
# add a user to the session
def addUserToSession(name):
session = fetchUsersSession()
user = { "user":name,"timeStamp":time.time() }
session.append(user)
saveUsersSession(session)
# update the session file
def updateSession():
session = fetchUsersSession()
new_session =list( filter(lambda x: time.time()-int(x["timeStamp"])<3600,session))
saveUsersSession(new_session)
def inSession(userName):
session = fetchUsersSession()
for user in session:
if user["user"] == userName:
return True
return False