esv/convert.py

194 lines
3.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# Convert.py
# Copyright (C) 2024 Judah Sotomayor
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
import pandas
import re
import os
import sys
titles = [
"Genesis",
"Exodus",
"Leviticus",
"Numbers",
"Deuteronomy",
"Joshua",
"Judges",
"Ruth",
"1 Samuel",
"2 Samuel",
"1 Kings",
"2 Kings",
"1 Chronicles",
"2 Chronicles",
"Ezra",
"Nehemiah",
"Esther",
"Job",
"Psalms",
"Proverbs",
"Ecclesiastes",
"Song of Solomon",
"Isaiah",
"Jeremiah",
"Lamentations",
"Ezekiel",
"Daniel",
"Hosea",
"Joel",
"Amos",
"Obadiah",
"Jonah",
"Micah",
"Nahum",
"Habakkuk",
"Zephaniah",
"Haggai",
"Zechariah",
"Malachi",
"Matthew",
"Mark",
"Luke",
"John",
"The Acts",
"Romans",
"1 Corinthians",
"2 Corinthians",
"Galatians",
"Ephesians",
"Philippians",
"Colossians",
"1 Thessalonians",
"2 Thessalonians",
"1 Timothy",
"2 Timothy",
"Titus",
"Philemon",
"Hebrews",
"James",
"1 Peter",
"2 Peter",
"1 John",
"2 John",
"3 John",
"Jude",
"Revelation"
]
abbreviations = [
"Ge",
"Exo",
"Lev",
"Num",
"Deu",
"Josh",
"Jdgs",
"Ruth",
"1Sm",
"2Sm",
"1Ki",
"2Ki",
"1Chr",
"2Chr",
"Ezra",
"Neh",
"Est",
"Job",
"Psa",
"Prv",
"Eccl",
"SSol",
"Isa",
"Jer",
"Lam",
"Eze",
"Dan",
"Hos",
"Joel",
"Amos",
"Obad",
"Jonah",
"Mic",
"Nahum",
"Hab",
"Zep",
"Hag",
"Zec",
"Mal",
"Mat",
"Mark",
"Luke",
"John",
"Acts",
"Rom",
"1Cor",
"2Cor",
"Gal",
"Eph",
"Phi",
"Col",
"1Th",
"2Th",
"1Tim",
"2Tim",
"Titus",
"Phmn",
"Heb",
"Jas",
"1Pet",
"2Pet",
"1Jn",
"2Jn",
"3Jn",
"Jude",
"Rev"
]
f = open(sys.argv[1])
json_list = json.load(f)
# The keys we need to extract from the json data
key_list = ['book', 'chapter', 'verse', 'text']
json_list = [{k:d[k] for k in key_list} for d in json_list]
df = pandas.json_normalize(json_list)
# Function to get book name
def get_name(row):
index = int(row["book"]) - 1
return abbreviations[index], titles[index]
df.insert(0, "name", '')
df.insert(0, "abbrev", '')
df[["name", "abbrev"]] = df.apply(get_name, axis=1, result_type='expand')
export_csv = df.to_csv('esv.tsv',
sep='\t',
encoding='utf-8',
header=False,
index=None)
# Sanity check the size of the file.
file_stats = os.stat("esv.tsv")
if file_stats.st_size != 4616589:
print("Warning: File appears different from recorded value")
print("Recorded value: 4616589")
print("Found value: ", file_stats.st_size)
else:
print("Conversion successful!")