Query fragments also by book id.
[wolnelektury.git] / scripts / make-locale-pack-json.py
1 #!/usr/bin/env python
2
3 import json
4 import sys
5 import os
6 import shutil
7
8 fname = sys.argv[1]
9 def mkdir(n):
10     if not os.path.exists(n): os.mkdir(n)
11
12 dst = os.path.dirname(fname)
13 name = os.path.basename(fname).split('.')[0]
14
15 dst2 = os.path.join(dst, name) 
16 mkdir(dst2)
17
18 data = json.load(open(fname))
19 for ip in data:
20     dst3 = os.path.join(dst2, ip['fields']['slug'])
21     mkdir(dst3)
22     for fld, val in ip['fields'].items():
23         if filter(lambda x: fld.startswith(x),
24                   ['title', 'left_column', 'right_column']):
25             o = open(os.path.join(dst3, fld+".txt"),'w')
26             try:
27                 o.write(val.encode('utf-8'))
28             finally:
29                 o.close()
30