forked from FlagBrew/Sharkive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
joiner.py
60 lines (53 loc) · 2.21 KB
/
joiner.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
#!/usr/bin/python3
import argparse
import os
import json
import bz2
parser = argparse.ArgumentParser(description = 'Sharkive cheat codes joiner')
parser.add_argument('type', help = '3ds, switch')
def main(args):
db = {}
if '3ds' in args.type:
for cheat in os.listdir('./db'):
with open(os.path.join('./db', cheat), 'r') as file:
titleid = cheat[:cheat.rfind('.')]
lines = [line.strip() for line in file]
lines = list(filter(None, lines))
db[titleid] = {}
selectedCheat = lines[0]
for line in lines:
if line.startswith('{') and line.endswith('}'):
pass
elif line.startswith('[') and line.endswith(']'):
selectedCheat = line[1:-1]
db[titleid][selectedCheat] = []
else:
db[titleid][selectedCheat].append(line)
elif 'switch' in args.type:
for root, _, files in os.walk('./switch'):
titleid = root[root.rfind('/')+1:]
if "switch" in titleid:
continue
db[titleid] = {}
for file in files:
buildid = file[:file.find('.')]
db[titleid][buildid] = {}
with open(os.path.join(root, file), 'r') as f:
lines = [line.strip() for line in f]
lines = list(filter(None, lines))
selectedCheat = lines[0]
for line in lines:
if line.startswith('{') and line.endswith('}'):
pass
elif line.startswith('[') and line.endswith(']'):
selectedCheat = line[1:-1]
db[titleid][buildid][selectedCheat] = []
else:
db[titleid][buildid][selectedCheat].append(line)
else:
exit(0)
compressed = bz2.compress(str.encode(json.dumps(db)))
with open(os.path.join('build', args.type + '.json.bz2'), 'wb') as f:
f.write(compressed)
if __name__ == '__main__':
main(parser.parse_args())