mirror of
https://github.com/getbible/v2_builder.git
synced 2024-11-22 02:35:09 +00:00
initial commit
This commit is contained in:
commit
fe6a98c602
52
sword_to_json.py
Normal file
52
sword_to_json.py
Normal file
@ -0,0 +1,52 @@
|
||||
from pysword.modules import SwordModules
|
||||
import argparse, json
|
||||
|
||||
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()
|
Loading…
Reference in New Issue
Block a user