-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-edge-metadata.py
49 lines (36 loc) · 1.23 KB
/
patch-edge-metadata.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
#!/usr/bin/env python3
import zipfile
import json
import sys
from os.path import join
import subprocess
def load(from_dir):
with open(join(from_dir, 'edges.json')) as f:
j = json.load(f)
for edge in j:
print(F"{edge['edgeId']}: {len(edge['metadata']['frames'])} frames")
return j
def patch(to_dir, data):
for edge in data:
eid = edge['edgeId']
with zipfile.ZipFile(join(to_dir, F'{eid}.zip'), 'r') as z:
metadata = json.loads(z.read('metadata.json'))
from_image = z.read('from.png')
to_image = z.read('to.png')
metadata['frames'] = edge['metadata']['frames']
metadata_str = json.dumps(metadata)
with zipfile.ZipFile('tmp.zip', 'w') as z2:
z2.writestr('from.png', from_image)
z2.writestr('to.png', to_image)
z2.writestr('metadata.json', metadata_str)
out = subprocess.check_output([
'mv',
'-v',
'tmp.zip',
join(to_dir, F'{eid}.zip')
])
print(out)
if __name__ == '__main__':
from_dir, to_dir, *_ = tuple(sys.argv[1:])
data = load(from_dir)
patch(to_dir, data)