-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.py
33 lines (28 loc) · 948 Bytes
/
converter.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
import json
from io import BytesIO
from tokenize import tokenize
from zipfile import ZipFile
from clausewitz.parse import parse
from clausewitz.util.tokenize import prepare
from pathlib import Path
def jsonify(f):
return parse(tokenize(prepare(f.readline)))
def unzip_save(f: BytesIO):
with ZipFile(f) as zip:
with zip.open('meta') as meta:
print("Parsing meta")
yield 'meta', meta
with zip.open('gamestate') as gamestate:
print("Parsing gamestate")
yield 'gamestate', gamestate
def savToJson(filelocation):
with open(filelocation, "rb") as save:
f = BytesIO(save.read())
result = {
name: jsonify(unzipped)
for name, unzipped in unzip_save(f)
}
print("done")
with open(Path(filelocation).stem + ".json", 'w') as json_f:
json.dump(result, json_f)
return result