forked from cheahjs/bfdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_ls.py
75 lines (61 loc) · 2.19 KB
/
extract_ls.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
#!/usr/bin/python
import json
import glob
import sys
import collections
import os
from to_json import *
from util import *
from leaderskill import parse_leader_skill
from braveburst import parse_skill
reload(sys) # Reload does the trick!
sys.setdefaultencoding('UTF8')
if __name__ == '__main__':
_dir = 'data/decoded_dat/'
dict_file = 'data/dictionary_raw.txt'
if len(sys.argv) > 1:
_dir = sys.argv[1]
if len(sys.argv) > 2:
dict_file = sys.argv[2]
files = {
'dict': dict_file,
'leader skill': _dir + 'Ver*_4dE8UKcw*',
}
jsons = {}
for name, filename in files.iteritems():
try:
with open(max(glob.iglob(filename), key=os.path.getctime)) as f:
if f.name.split('.')[-1] == 'txt' or f.name.split('.')[-1] == 'csv':
jsons[name] = dict([
line.split('^')[:2] for line in f.readlines() if len(line.split('^')) >= 2
])
else:
jsons[name] = json.load(f)
except Exception, e:
pass
if 'jp' in sys.argv:
jsons['dict'] = {}
def key_by_id(lst, id_str):
return {obj[id_str]: obj for obj in lst}
leader_skills = key_by_id(jsons['leader skill'], LS_ID)
#skills_data = {}
#for skill in skills:
# skill_data = parse_skill(None, skills[skill], bbs[skill], jsons['dict'])
# skills_data[skill] = skill_data
leader_skills_data = {}
for ls in leader_skills:
ls_data = parse_leader_skill(None, leader_skills[ls], jsons['dict'], 'jp' in sys.argv)
leader_skills_data[ls] = ls_data
#dump_data = {'bbs': skills_data, 'leader skills': leader_skills_data}
dump_data = leader_skills_data
if 'jp' in sys.argv:
print json.dumps(dump_data,
sort_keys=True,
indent=4,
cls=IndentlessEncoder,
ensure_ascii=False).encode('utf8').replace('"[', '[').replace(']"', ']')
else:
print json.dumps(dump_data,
sort_keys=True,
indent=4,
cls=IndentlessEncoder).replace('"[', '[').replace(']"', ']')