-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-sketch.py
39 lines (33 loc) · 1.12 KB
/
new-sketch.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
import argparse
import json
import shutil
parser = argparse.ArgumentParser()
parser.add_argument("name", help="name of sketch")
parser.add_argument("type", help="type of sketch", choices=["d3", "p5"])
args = parser.parse_args()
with open('./sketch-index.json', 'r') as index_file:
index = json.load(index_file)
assert args.name not in index
index[args.name] = {
'id': args.name,
'type': args.type,
'title': args.name.capitalize(),
'description': [],
"gui": []
}
print('creating new sketch:')
print(json.dumps(index[args.name], indent=4))
while True:
proceed = input('continue? y/n: ')
if proceed.lower() == 'y':
with open('./sketch-index.json', 'w') as index_write:
index_write.write(json.dumps(index, indent=4))
if args.type == 'd3':
shutil.copy('./editor/components/templated3.js', f'./editor/sketchfiles/{args.name}.js')
elif args.type == 'p5':
shutil.copy('./editor/components/templatep5.js', f'./editor/sketchfiles/{args.name}.js')
break
elif proceed.lower() == 'n':
break
else:
print('please input y or n')