-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimerHandlers.py
156 lines (128 loc) · 4.03 KB
/
TimerHandlers.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import requests
import json
from pprint import pprint
import asyncio
import os
import sys
import _json
if getattr(sys, 'frozen', False):
# frozen
dir_ = os.path.dirname(sys.executable)
else:
# unfrozen
dir_ = os.path.dirname(os.path.realpath(__file__))
timerDir = os.path.join( os.path.abspath(dir_), "timers")
timerFilePath = os.path.join(timerDir, "timers")
fourmPath = os.path.join( os.path.abspath(dir_), "fourms")
def createRaidTimer(timerData):
raidTimerFile = open(os.path.join(timerDir, 'raid.json'), 'w+')
json.dump(timerData, raidTimerFile)
def saveRaidTimer(timerData):
raidTimerFile = open(os.path.join(timerDir, 'raid.json'), 'w+')
json.dump(timerData, raidTimerFile)
def deleteRaidTimer():
raidTimerFile = open(os.path.join(timerDir, 'raid.json'), 'w+')
raidTimerFile.close()
def readRaid():
try:
raidTimerFile = open(os.path.join(timerDir, 'raid.json'), 'r')
raidTimerJSON = json.load(raidTimerFile)
raidTimerFile.close()
return raidTimerJSON
except:
return -1
def readSpecificRaidTimer(raidTimer):
try:
raidTimerFile = open(os.path.join(fourmPath, raidTimer), 'r')
raidTimer = raidTimerFile.readline()
raidTimerFile.close()
return raidTimer
except:
return -1
def readSpecificRaidTimerData(raidTimer):
try:
raidTimerFile = open(os.path.join(fourmPath, raidTimer + ".responses"), 'r')
raidTimer = raidTimerFile.readline()
raidTimerFile.close()
return raidTimer
except:
return -1
def updateAcceptedUserList(timerData):
userFile = open(os.path.join(timerDir, 'acceptedUsers.json'), 'w+')
json.dump(timerData, userFile)
def readAcceptedUserList():
try:
userFile = open(os.path.join(timerDir, 'acceptedUsers.json'), 'r')
userJSON = json.load(userFile)
return userJSON
except:
return -1
def createRaffleTimer(timerData):
raffleTimerFile = open(os.path.join(timerDir, 'raffle.json'), 'w+')
json.dump(timerData, raffleTimerFile)
def readRaffle():
try:
raffleTimerFile = open(os.path.join(timerDir, 'raffle.json'), 'r')
raffleJSON = json.load(raffleTimerFile)
return raffleJSON
except:
return -1
def deleteTimer(senderID, timerList):
try:
del timerList[senderID]
return True
except KeyError:
return False
def checkTimer(id, timerList, key):
if id in timerList:
killCount = getInfo(key)
return killCount - timerList[id]
else:
timerList[id] = getInfo(key)
return False
def checkTotalKills(id, timerList, key):
if id in timerList:
killCount = getInfo(key)
return timerList[id]
else:
timerList[id] = getInfo(key)
return False
def startTimer(id, timerList, key):
timerList[id] = getInfo(key)
return timerList
def getInfo(key):
info = requests.get("https://api.guildwars2.com/v2/account/achievements/?access_"
"token=" + key)
infoJSON = info.json()
for item in infoJSON:
if item["id"] == 283:
print(item["current"])
return item["current"]
pprint(infoJSON)
return -1
def readAPIKeys():
if not os.path.exists(APIKeyDir):
os.makedirs(APIKeyDir)
if os.path.isfile(APIKeyFilePath) and os.stat(APIKeyFilePath).st_size != 0:
APIFile = open(APIKeyFilePath).read()
APIData = json.loads(APIFile)
pprint(APIData)
return APIData
else:
return {}
def readTimers():
if not os.path.exists(timerDir):
os.makedirs(timerDir)
if os.path.isfile(timerFilePath) and os.stat(timerFilePath).st_size != 0:
timerFile = open(timerFilePath).read()
timerData = json.loads(timerFile)
pprint(timerData)
return timerData
else:
return {}
def writeTimerList(timersToWrite):
f = open(timerFilePath, "w+")
json.dump(timersToWrite, f)
def writeAPIKeys(keysToWrite):
f = open(APIKeyFilePath, "w+")
json.dump(keysToWrite, f)