-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweak_templates.py
55 lines (44 loc) · 1.42 KB
/
tweak_templates.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
import sys
from pathlib import Path
checklist_portrait = r""" {
"name": "Checklist",
"filename": "P Checklist",
"iconCode": "\ue98f",
"categories": [
"Life/organize"
]
},"""
positivity_journal = r""" {
"name": "Positivity Journal",
"filename": "PositivityJournal",
"iconCode": "\ue98f",
"categories": [
"Life/organize"
]
},"""
travel_checklist = r""" {
"name": "Travel Checklist",
"filename": "TravelChecklist",
"iconCode": "\ue98f",
"categories": [
"Life/organize"
]
},"""
def add_entry(filename, to_find, to_add):
with Path(filename).open('r') as json_file_in:
json_data = json_file_in.read()
if not json_data.find(to_find):
print('Cannot find the hook template.')
return
if json_data.find(to_add) != -1:
print('The template to be added is already there.')
return
json_data = json_data.replace(to_find, to_find + '\n' + to_add + '\n')
with Path(filename).open('w') as json_file_in:
json_file_in.write(json_data)
if __name__ == '__main__':
if (len(sys.argv) < 2) or not sys.argv[1].endswith('.json'):
print('Usage: tweak_templates path/to/templates.json')
print(f'Modifying {sys.argv[1]}')
add_entry(sys.argv[1], checklist_portrait, positivity_journal)
add_entry(sys.argv[1], checklist_portrait, travel_checklist)