-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
30 lines (26 loc) · 906 Bytes
/
make.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
from __future__ import print_function
try:
from urllib.parse import quote
except:
from urllib import quote
with open('bookmarklet.js') as f:
result = []
for idx, line in enumerate(f.readlines()):
comment = '//'
if comment in line:
line = line[:line.index(comment)]
line = line.strip()
if line and line[-1] not in '`,{};[':
print('Line {} may have bad ending: {}'.format(idx, line))
result.append(line)
code = ''.join(result)
code = quote(code)
bookmarklet = 'javascript:(function(){'+code+'})();'
with open('README.md.template') as f:
readme = f.read()
#with open('README.md', 'w') as f:
# #f.write(readme.format(BOOKMARKLET=bookmarklet))
# f.write(readme.replace('{BOOKMARKLET}', bookmarklet))
import json
with open('../_data/recipe.json', 'w') as f:
json.dump(dict(BOOKMARKLET=bookmarklet), f)