-
Notifications
You must be signed in to change notification settings - Fork 14
/
soloraidar.py
106 lines (90 loc) · 3.71 KB
/
soloraidar.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
__author__ = "Toeofdoom"
import time
import sys
import os.path
from evtcparser import *
from analyser import *
from enum import IntEnum
import json
from zipfile import ZipFile
import argparse
def is_basic_value(node):
try:
dict(node)
return False
except:
return True
def flatten(root):
nodes = dict((key, dict(node)) for key,node in root.items())
stack = list(nodes.keys())
for node_name in stack:
node = nodes[node_name]
for child_name, child in node.items():
try:
full_child_name = "{0}-{1}".format(node_name, child_name)
nodes[full_child_name] = dict(child)
stack.append(full_child_name)
except TypeError:
pass
except ValueError:
pass
return nodes
def format_value(value):
if isinstance(value, IntEnum):
return value.name
else:
return value
def print_node(key, node, f=None):
basic_values = list(filter(lambda key:is_basic_value(key[1]), node.items()))
if basic_values:
output_string = "{0}: {1}".format(key, ", ".join(
["{0}:{1}".format(name, format_value(value)) for name,value in basic_values]))
print(output_string, file=f)
def main():
zipfile = None
argparser = argparse.ArgumentParser(description='Process some integers.')
argparser.add_argument('filenames', metavar='N', type=str, nargs='+',
help='the files to load')
argparser.add_argument('-s', dest='silent', action='store_true',
help='silent mode, no output dump')
argparser.add_argument('--no-json', dest='json', action='store_false',
help='disable json output')
args = argparser.parse_args()
start_all = time.clock()
print("Parsing {0}".format(args.filenames))
for filename in args.filenames:
print("Loading {0}".format(filename))
with open(filename, mode='rb') as file:
if filename.endswith('.evtc.zip') or filename.endswith('.zevtc'):
zipfile = ZipFile(file)
contents = zipfile.infolist()
if len(contents) == 1:
file = zipfile.open(contents[0].filename)
else:
print('Only single-file ZIP archives are allowed', file=sys.stderr)
sys.exit(1)
start = time.clock()
e = parser.Encounter(file)
print("Parsing took {0} seconds".format(time.clock() - start))
print("Evtc version {0}".format(e.version))
start = time.clock()
a = analyser.Analyser(e)
print("Analyser took {0} seconds".format(time.clock() - start))
start = time.clock()
with open('Output/'+os.path.basename(filename)+'.txt','w',encoding='utf-8') as output_file:
flattened = flatten(a.data)
for key in sorted(flattened.keys()):
if not args.silent:
print_node(key, flattened[key])
print_node(key, flattened[key], output_file)
print("Completed parsing {0} - Success: {1}".format(
list(a.data['Category']['boss']['Boss'].keys())[0],
a.data['Category']['encounter']['success']))
print("Readable dump took {0} seconds".format(time.clock() - start))
if "--no-json" not in sys.argv:
start = time.clock()
print(json.dumps(a.data), file=open('output.json','w'))
print("JSon dump took {0} seconds".format(time.clock() - start))
print("Analysing all took {0} seconds".format(time.clock() - start_all))
if __name__ == "__main__":
main()