-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContestManager.py
More file actions
101 lines (81 loc) · 2.76 KB
/
Copy pathContestManager.py
File metadata and controls
101 lines (81 loc) · 2.76 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import dataBASS
import OTOG_API
import time
def timeParse(con: str):
con = con[: con.find(".")] + "Z"
return time.mktime(time.strptime(con, "%Y-%m-%dT%H:%M:%SZ"))
def verifyState():
# state -3 is so longggg
# state -2 is 1 day
# state -1 is 1 hour
# state 0 is now
if time.time() > timeParse(dataBASS.contest["info"]["timeStart"]):
state = 0
elif time.time() > timeParse(dataBASS.contest["info"]["timeStart"]) - 60 * 60:
state = -1
elif time.time() > timeParse(dataBASS.contest["info"]["timeStart"]) - 60 * 60 * 24:
state = -2
else:
state = -3
dataBASS.contest["state"] = state
def reVerState():
if time.time() > timeParse(dataBASS.contest["info"]["timeStart"]):
nState = 0
elif time.time() > timeParse(dataBASS.contest["info"]["timeStart"]) - 60 * 60:
nState = -1
elif time.time() > timeParse(dataBASS.contest["info"]["timeStart"]) - 60 * 60 * 24:
nState = -2
else:
nState = -3
if dataBASS.contest["state"] != nState and dataBASS.contest["ann"]:
dataBASS.contest["state"] = nState
if nState != 0:
dataBASS.contest["ann"] = False
def mkNewContest(otogCon):
dataBASS.contest = {"info": otogCon, "state": 0, "ann": False}
verifyState()
dataBASS.saveFile()
def timeState():
if "info" not in dataBASS.contest:
return "NoContest"
else:
timeStart = timeParse(dataBASS.contest["info"]["timeStart"])
timeEnd = timeParse(dataBASS.contest["info"]["timeEnd"])
if time.time() < timeStart:
return "NotStart"
elif time.time() < timeEnd:
return "NotEnd"
else:
return "NoContest"
def reloading():
if not OTOG_API.isWorking():
return
otogCon = OTOG_API.contestNow()
if otogCon != -1:
if "timeEnd" not in otogCon:
dataBASS.contest = dict()
dataBASS.saveFile()
return
else:
timeStart = timeParse(otogCon["timeStart"])
timeEnd = timeParse(otogCon["timeEnd"])
if time.time() > timeEnd:
dataBASS.contest = dict()
dataBASS.saveFile()
else:
if "info" not in dataBASS.contest:
mkNewContest(otogCon)
elif dataBASS.contest["info"]["id"] != otogCon["id"]:
mkNewContest(otogCon)
elif dataBASS.contest["info"]["timeStart"] != otogCon["timeStart"]:
mkNewContest(otogCon)
else:
dataBASS.contest["info"] = otogCon
dataBASS.saveFile()
def isDuringContest():
if "info" not in dataBASS.contest:
return False
else:
return dataBASS.contest["state"] == 0
if __name__ == "__main__":
reloading()