-
Notifications
You must be signed in to change notification settings - Fork 14
/
sword_to_json.py
56 lines (44 loc) · 1.69 KB
/
sword_to_json.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
56
from pysword.modules import SwordModules
import argparse, json, sys
if sys.version_info > (3, 0):
from past.builtins import xrange
def generate_dict(source_file, bible_version):
modules = SwordModules(source_file)
found_modules = modules.parse_modules()
bible = modules.get_bible_from_module(bible_version)
books = bible.get_structure()._books['ot'] + bible.get_structure()._books['nt']
bib = {}
bib['books'] = []
for book in books:
chapters = []
for chapter in xrange(1, book.num_chapters+1):
verses = []
for verse in xrange(1, len(book.get_indicies(chapter))+1 ):
verses.append({
'verse': verse,
'chapter': chapter,
'name': book.name + " " + str(chapter) + ":" + str(verse),
'text': bible.get(books=[book.name], chapters=[chapter], verses=[verse])
})
chapters.append({
'chapter': chapter,
'name': book.name + " " + str(chapter),
'verses': verses
})
bib['books'].append({
'name': book.name,
'chapters': chapters
})
return bib
def write_json(bible_dict, output_file):
with open(output_file, 'w') as outfile:
json.dump(bible_dict, outfile)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--source_file')
parser.add_argument('--bible_version')
parser.add_argument('--output_file')
args = parser.parse_args()
bible_dict = generate_dict(args.source_file, args.bible_version)
write_json(bible_dict, args.output_file)
if __name__ == "__main__": main()