-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathgenerate_b64_mocks.py
50 lines (37 loc) · 1.09 KB
/
generate_b64_mocks.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
import os
import sys
import json
import plotly.io as pio
from convert_b64 import arraysToB64
args = []
if len(sys.argv) == 2 :
args = sys.argv[1].split()
elif len(sys.argv) > 1 :
args = sys.argv
root = os.getcwd()
dirIn = os.path.join(root, 'test', 'image', 'mocks')
dirOut = dirIn
print('output to', dirOut)
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
ALL_MOCKS.sort()
if len(args) > 0 :
allNames = [a for a in args if a in ALL_MOCKS]
else :
allNames = ALL_MOCKS
if len(allNames) == 0 :
print('error: Nothing to create!')
sys.exit(1)
for name in allNames :
outName = name
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
fig = json.load(_in)
before = json.dumps(fig, indent = 2)
newFig = dict()
arraysToB64(fig, newFig)
fig = newFig
after = json.dumps(fig, indent = 2)
if before != after :
print(outName)
_out = open(os.path.join(dirOut, outName + '.json'), 'w')
_out.write(json.dumps(fig, indent = 2))
_out.close()