Last active
March 27, 2017 18:37
-
-
Save dnnyg33/d75edcb7b4e130b7d2618b5ce9789693 to your computer and use it in GitHub Desktop.
convert sql bible file to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import json | |
import argparse | |
parser = argparse.ArgumentParser(description='Convert bible sql to json') | |
parser.add_argument('-f', '--file', type=str, help='Full path to input Bible sql file to read', required=True) | |
parser.add_argument('-o', '--oldTestament', dest='old', action='store_true', help='Output the Old testament') | |
parser.add_argument('-n', '--newTestament', dest='old', action='store_false', help='Output the New testament') | |
args = parser.parse_args() | |
conn = sqlite3.connect(args.file) | |
cursor = conn.cursor() | |
books = [] | |
newTestament = "('Matt', 'Mark', 'Luke', 'John', 'Acts', 'Rom', '1Cor', '2Cor', 'Gal', 'Eph','Phil','Col','1Thess','2Thess','1Tim','2Tim','Titus','Phlm','Heb', 'Jas','1Pet','2Pet','1John','2John','3John','Jude','Rev')" | |
selectStatement = "SELECT * FROM books WHERE osis IN " + newTestament | |
if args.old is True: | |
selectStatement = "SELECT * FROM books WHERE osis NOT IN " + newTestament | |
for row in cursor.execute(selectStatement): | |
book = {"chapters": row[3], "title": row[2], "tag": row[1]} | |
books.append(book) | |
standardWork = {} | |
for book in books: | |
chapters = {} | |
for x in range(0, book["chapters"]): | |
chapter = {} | |
where = "'" + str(x +1) + ".%'" | |
for row in cursor.execute("SELECT * FROM verses WHERE book = '" + book["tag"] + | |
"' AND verse LIKE " + where + " order by verse"): | |
verseNumber = str(row[2]).split('.')[1] | |
chapter[str(int(verseNumber))] = row[3] | |
chapters[str(x + 1)] = chapter | |
standardWork[book["title"]] = chapters | |
print json.dumps(standardWork) |
Usage:
python bible_sqlite.py -f '/Users/dgeorge/Downloads/niv.sqlite3' -n > niv_new.json
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
converts sql files located at this repo
https://github.com/liudongmiao/bibledata