-
Notifications
You must be signed in to change notification settings - Fork 1
/
item_json_parser_v2.py
320 lines (250 loc) · 8.02 KB
/
item_json_parser_v2.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import json
import operator
def recurprint(data,poststr,f):
if type(data) != dict and type(data) != list:
if 'items' in poststr+data:
f.write(poststr+data+'\n')
#print poststr+data
return
if type(data) == dict:
for key in data:
recurprint(data[key],poststr+key+'|',f)
if type(data) == list:#WHO MAKES A LIST OF DICKS
for item in data:
f.write('\n')
#print
recurprint(item,poststr,f)
def heroToNum(herostr):
heroes=['ana','bastion','dva','genji',\
'hanzo','junkrat','lucio','mccree',\
'mei','mercy','orisa','pharah','reaper',\
'reinhardt','roadhog','soldier-76','sombra',\
'symmetra','torbjorn','tracer','widowmaker',\
'winston','zarya','zenyatta','all']
for i in range(len(heroes)):
if heroes[i] == herostr:
return i+1
return -1
def rarityToNum(rarestr):
rarities=['common','rare','epic','legendary']
for i in range(len(rarities)):
if rarities[i] == rarestr:
return i+1
return -1
def typeToNum(typestr):
types=['icons','sprays','skins','emotes','intros','voicelines','poses']
for i in range(len(types)):
if types[i] == typestr:
return i+1
return -1
def eventToNum(eventstr):
events=['HALLOWEEN_2016','SUMMER_GAMES_2016','UPRISING_2017','WINTER_WONDERLAND_2016','YEAR_OF_THE_ROOSTER_2017']
for i in range(len(events)):
if events[i] == eventstr:
return i+1
return -1
def achievementToNum(achievementstr):
achievements=['true','blizzard']
for i in range(len(achievements)):
if achievements[i] == achievementstr:
return i+1
return -1
def addinfo(itemdic,arr):
itemdic['he']=heroToNum(arr[0])
itemdic['ty']=typeToNum(arr[2])
if arr[3] == 'name':
itemdic['na']=arr[4]
if arr[3] == 'quality':
itemdic['ra']=rarityToNum(arr[4])
if arr[3] == 'id': ##copy over id from that websit https://js41637.github.io/Overwatch-Item-Tracker/
itemdic['jid']=arr[4]
if arr[3] == 'event':
itemdic['ev']=eventToNum(arr[4])
if arr[3] == 'achievement':
itemdic['ac']=achievementToNum(arr[4])
if arr[3] == 'standardItem':
itemdic['de']=1
return itemdic
def apply_defaults(itemdic):
if itemdic['ra']==0:
if itemdic['ty']==typeToNum('sprays'):
itemdic['ra']=rarityToNum('common')
if itemdic['ty']==typeToNum('icons'):
itemdic['ra']=rarityToNum('rare')
#calculate costs for normies
if itemdic['ev']==0 and itemdic['ac']==0 and itemdic['de']==0 and itemdic['ty'] != typeToNum('icons'):
if itemdic['ra']==1:
itemdic['co']=25
elif itemdic['ra']==2:
itemdic['co']=75
elif itemdic['ra']==3:
itemdic['co']=250
elif itemdic['ra']==4:
itemdic['co']=1000
#calculate costs for eventos
if itemdic['ev']!=0 and itemdic['ac']==0 and itemdic['ty'] != typeToNum('icons'):
if itemdic['ra']==1:
itemdic['co']=75
elif itemdic['ra']==2:
itemdic['co']=225
elif itemdic['ra']==3:
itemdic['co']=750
elif itemdic['ra']==4:
itemdic['co']=3000
##
## if itemdic['event']=='unknown':
## itemdic['event']='none'
return itemdic
def explodestr(strin):
x=strin.find('|')
if x== -1:
return ['INVALID']
x=strin.split('|')
y=x[:-1]
y.append(x[-1][0:-1])
return y
level=0
linearr=[]
with open('items.json') as json_data:
data = json.load(json_data)
##help(data)
f=open('jsonoutput.txt','w')
recurprint(data,'',f)
f.close()
f=open('jsonoutput.txt','r')
itemtemplate={'hero':'unknown','type':'unknown',\
'rarity':'unknown','event':'none',\
'achievement':'none','cost':'0',\
'dupval':'0','id':'0','iname':'0','getinbox':'yes','default':'no'}
itemtemplate={'he':0,'ty':0,\
'ra':0,'ev':0,\
'ac':0,'co':0,\
'id':0,\
'na':'idk',\
'de':0,'ck':0,'jid':'str'}
itemdic=itemtemplate
itemlist=[]
counter=1
for line in f:
arr=explodestr(line)
if arr[0] != 'INVALID':
#pass
#print arr
itemdic=addinfo(itemdic,arr)
else:
#print itemdic
if (itemdic['ty']==typeToNum('icons') and itemdic['he']!=heroToNum('all')) or itemdic['he'] == 0:
pass
else:
itemdic=apply_defaults(itemdic)
itemdic['id']=counter
#print itemdic
itemlist.append(itemdic)
counter+=1
itemdic={'he':0,'ty':0,\
'ra':0,'ev':0,\
'ac':0,'co':0,\
'id':0,\
'na':'idk',\
'de':0,'ck':0,'jid':'str'}
## 'he' - hero heroToNum('all')
## 'ty' - type typeToNum('icons')
## 'ra' - rarity rarityToNum('common'
## 'ev' - event
## 'ac' - achievement
## 'co' - cost
## 'id' - id
## 'na' - name
## 'de' - default
## 'w' - want checkmark
## 'h' - havecheckmark
##handle the last item
itemdic=apply_defaults(itemdic)
itemdic['id']=counter
itemlist.append(itemdic)
#sort stuff
itemlist.sort(key=operator.itemgetter('ac'))
itemlist.sort(key=operator.itemgetter('ev'))
itemlist.sort(key=operator.itemgetter('ra'))
itemlist.reverse()
itemlist.sort(key=operator.itemgetter('ty'))
itemlist.sort(key=operator.itemgetter('he'))
#renumber objects
for i in range(len(itemlist)):
itemlist[i]['id']=i
#list out possible objects you could get
commonarr=[]
for i in range(len(itemlist)):
if itemlist[i]['ty']!=typeToNum('icons') and \
itemlist[i]['ev']==0 and \
itemlist[i]['ac']==0 and \
itemlist[i]['ra']==rarityToNum('common'):
commonarr.append(i)
rarearr=[]
for i in range(len(itemlist)):
if (itemlist[i]['ev']==0 and \
itemlist[i]['ac']==0 and \
itemlist[i]['ra']==rarityToNum('rare')) or itemlist[i]['ty']==typeToNum('icons'):
rarearr.append(i)
epicarr=[]
for i in range(len(itemlist)):
if itemlist[i]['ty']!=typeToNum('icons') and \
itemlist[i]['ev']==0 and \
itemlist[i]['ac']==0 and \
itemlist[i]['ra']==rarityToNum('epic'):
epicarr.append(i)
legarr=[]
for i in range(len(itemlist)):
if itemlist[i]['ty']!=typeToNum('icons') and \
itemlist[i]['ev']==0 and \
itemlist[i]['ac']==0 and \
itemlist[i]['ra']==rarityToNum('legendary'):
legarr.append(i)
objectstr=''
for idd in itemlist:
objectstr+=''+str(idd)+','
commonstr=''
for idd in commonarr:
commonstr+=''+str(idd)+','
rarestr=''
for idd in rarearr:
rarestr+=''+str(idd)+','
epicstr=''
for idd in epicarr:
epicstr+=''+str(idd)+','
legstr=''
for idd in legarr:
legstr+=''+str(idd)+','
f.close()
f=open('item_output.js','w')
f.write('''
/*
## 'he' - HERO NUMBER: order (ana is 1) =
['ana','bastion','dva','genji',\
'hanzo','junkrat','lucio','mccree',\
'mei','mercy','orisa','pharah','reaper',\
'reinhardt','roadhog','soldier-76','sombra',\
'symmetra','torbjorn','tracer','widowmaker',\
'winston','zarya','zenyatta','all']
## 'ty' - TYPE ['icons','sprays','skins','emotes','intros','voicelines','poses']
## 'ra' - RARITY ['common','rare','epic','legendary']
## 'ev' - EVENT (0 is no event, 1 is halloween)....['HALLOWEEN_2016','SUMMER_GAMES_2016',
'UPRISING_2017','WINTER_WONDERLAND_2016',
'YEAR_OF_THE_ROOSTER_2017']
## 'ac' - ACHIEVEMENT ['true','blizzard']
## 'co' - COST
## 'id' - ID NUMBER
## 'na' - NAME
## 'de' - DEFAULT ITEM
## 'wck' - CHECKBOX (0: no checks, 1: has check, 2: want,
3: has check and has disable, 4: no check want disable)
*/
''')
f.write('var itemarr=['+objectstr[:-1]+'];') #remove trailing comma
f.write('''
var commonbox=['''+commonstr[:-1]+'''];
var rarebox=['''+rarestr[:-1]+'''];
var epicbox=['''+epicstr[:-1]+'''];
var legbox=['''+legstr[:-1]+'''];
''')
f.close()