-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIJSONParser.py
More file actions
128 lines (90 loc) · 3.25 KB
/
APIJSONParser.py
File metadata and controls
128 lines (90 loc) · 3.25 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
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
from contants import *
### DONE
def getFirstPageWeaponData(a_weaponData):
weaponName = a_weaponData["name"]
tmpArr = []
if "range" in a_weaponData:
if a_weaponData["range"] != 0:
tmpArr.append(("{0}\"").format(a_weaponData["range"]))
if "attacks" in a_weaponData:
if a_weaponData["attacks"] != 0:
tmpArr.append(("A{0}").format(a_weaponData["attacks"]))
for specialRule in a_weaponData["specialRules"]:
tmpArr.append(specialRule["label"])
triplets = fromCollectionToStringifyTriplets(tmpArr)
return { "weaponName" : weaponName, "trinkets" : triplets }
### DONE
def getGainData(a_gainObject):
tmpArr = []
name = a_gainObject["name"]
if "content" in a_gainObject:
if len(a_gainObject["content"]) != 0:
contents = []
for content in a_gainObject["content"]:
contentName = content["name"]
if "rating" in content:
contentName = ("{0}({1})").format(contentName, content["rating"])
tmpArr.append(contentName)
if "range" in a_gainObject:
if a_gainObject["range"] != 0:
tmpArr.append(("{0}\"").format(a_gainObject["range"]))
if "attacks" in a_gainObject:
if a_gainObject["attacks"] != 0:
tmpArr.append(("A{0}").format(a_gainObject["attacks"]))
if "specialRules" in a_gainObject:
if len(a_gainObject["specialRules"]) != 0:
for specRule in a_gainObject["specialRules"]:
if "rating" in specRule:
tmpSpecRuleString = specRule["name"] + "(" + str(specRule["rating"]) + ")"
else:
tmpSpecRuleString = specRule["name"]
tmpArr.append(tmpSpecRuleString)
#triplets = fromCollectionToStringifyTriplets(tmpArr)
triplets = tmpArr
return { "gainName" : name, "gainSpecRule" : triplets }
### DONE
def getFirstPageData(a_unit):
rulesCollection = []
for rule in a_unit["rules"]:
rulesCollection.append(rule["label"])
finalRules = fromCollectionToStringifyTriplets(rulesCollection)
quaDefString = ("Qua +{0} Def +{1}").format(a_unit["quality"], a_unit["defense"])
weaponsData = []
for weaponData in a_unit["weapons"]:
weaponsData.append(getFirstPageWeaponData(weaponData))
return { "name" : a_unit["name"], "unitTrinkets" : finalRules, "quaDef" : quaDefString, "weaponsData" : weaponsData }
### DONE
def getUnitUpgrades(a_unit, a_totalUpgrades):
upgradesList = []
for unitUpgrade in a_unit["upgrades"]: # just some ids from users
for upgradePack in a_totalUpgrades:
if upgradePack["uid"] != unitUpgrade:
continue
unitId = a_unit["id"]
upgrade = {}
for upgradeSection in upgradePack["sections"]:
upgrade["upgradeName"] = upgradeSection["label"]
options = []
for iOption in upgradeSection["options"]:
option = {}
### cost block
option["cost"] = 0
if "cost" in iOption:
option["cost"] = iOption["cost"]
if 'costs' in iOption:
for cost in iOption["costs"]:
if cost["unitId"] == unitId:
option["cost"] = cost["cost"]
### end cost block
### gains block
gains = []
for gain in iOption["gains"]:
gainData = getGainData(gain)
gains.append({"gainName":gainData["gainName"],"gainSpecRule":gainData["gainSpecRule"]})
option["gains"] = gains
### end gains block
options.append(option)
upgrade["options"] = options
upgradesList.append(upgrade.copy())
upgrade.clear()
return upgradesList