Created
April 30, 2019 10:55
-
-
Save avdyushin/0555221cb4703ca5ba4f55038d253964 to your computer and use it in GitHub Desktop.
Conver Unbound Bible format into SQL
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
#!/usr/bin/python | |
import fileinput | |
version = "kjv" | |
header = """-- | |
-- | |
-- | |
DROP TABLE IF EXISTS {}_bible_books; | |
CREATE TABLE {}_bible_books ( | |
id SMALLINT NOT NULL PRIMARY KEY, | |
book VARCHAR(40) NOT NULL, | |
alt VARCHAR(20) NOT NULL, | |
abbr VARCHAR(20) NOT NULL, | |
UNIQUE (book, alt, abbr) | |
); | |
INSERT INTO {}_bible_books VALUES""" | |
print header.format(version, version, version) | |
for line in fileinput.input(): | |
if line.startswith('#'): | |
continue | |
(b_index, name) = line.split(None, 1) | |
b_index = b_index.replace('O', '').replace('N', '') | |
name = name.rstrip() | |
try: | |
print '({:02}, "{}", "{}", "{}"),'.format(int(b_index), name, name, name) | |
except ValueError: | |
continue |
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
#!/usr/bin/python | |
import fileinput | |
version = "kjv" | |
header = """-- | |
-- | |
-- | |
DROP TABLE IF EXISTS {}_bible; | |
CREATE TABLE {}_bible ( | |
book_id SMALLINT NOT NULL, | |
chapter SMALLINT NOT NULL, | |
verse SMALLINT NOT NULL, | |
text TEXT NOT NULL, | |
PRIMARY KEY (book_id, chapter, verse) | |
); | |
INSERT INTO {}_bible (book_id, chapter, verse, text) VALUES""" | |
print header.format(version, version, version) | |
for line in fileinput.input(): | |
if line.startswith('#'): | |
continue | |
(b_index, chapter, verse, _, text) = line.split(None, 4) | |
# Keep only N and O canonic books | |
b_index = b_index.replace('O', '').replace('N', '') | |
try: | |
print '({:02}, {}, {}, "{}"),'.format(int(b_index), chapter, verse, text.rstrip()) | |
except ValueError: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment