-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIKeyHandler.py
More file actions
37 lines (32 loc) · 1.31 KB
/
APIKeyHandler.py
File metadata and controls
37 lines (32 loc) · 1.31 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
import requests
from pprint import pprint
import item
import itemPrice
def doesUserHaveKey(apiKeyCache, user):
if user in apiKeyCache:
return apiKeyCache[user]
return False
def getUserMaterials(apiKeyCache, user):
key = doesUserHaveKey(apiKeyCache, user)
if not key:
return -1
matInfo = requests.get("https://api.guildwars2.com/v2/account/materials/?access_"
"token=" + key)
matInfoJSON = matInfo.json()
pprint(matInfo)
return matInfoJSON
def compareMatsToNeededItems(matList, neededList, idList, rawTreasury):
haveList = {}
test = rawTreasury
for material in matList:
try:
matName = idList[material["id"]].name
if matName in neededList:
if rawTreasury[matName].totalAmount - rawTreasury[matName].curentAmount > 0 and material["count"] > 0:
if material["count"] > rawTreasury[matName].totalAmount - rawTreasury[matName].curentAmount:
haveList[matName] = item.Item(material["id"], matName,rawTreasury[matName].totalAmount - rawTreasury[matName].curentAmount, None)
else:
haveList[matName] = item.Item(material["id"], matName, material["count"], None)
except KeyError:
pass
return haveList