-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwvwFunctions.py
92 lines (76 loc) · 2.31 KB
/
wvwFunctions.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
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__))
APIKeyDir = logPath = os.path.join( os.path.abspath(dir_), "APIKeys")
APIKeyFilePath = logPath = os.path.join(APIKeyDir, "APIKeys")
timerDir = logPath = os.path.join( os.path.abspath(dir_), "timers")
timerFilePath = logPath = os.path.join(timerDir, "timers")
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)