feat[converter] Added converter tools

I added converter tools and a download task to make.
This ensures I can distribute the program without running into legal
issues about distributin the ESV.
This commit is contained in:
Judah Sotomayor 2024-03-04 21:19:45 -05:00 committed by Judah
parent cb1f6c8608
commit fc86a09bbf
4 changed files with 200 additions and 2 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
esv
ESV.json
esv.tsv
esv.zip

View File

@ -4,6 +4,7 @@
PREFIX = /usr/local
esv: esv.sh esv.awk esv.tsv
cat esv.sh > $@
echo 'exit 0' >> $@
@ -15,7 +16,7 @@ test: esv.sh
shellcheck -s sh esv.sh
clean:
rm -f esv
rm -f esv ESV.json esv.zip
install: esv
mkdir -p $(DESTDIR)$(PREFIX)/bin
@ -25,6 +26,24 @@ install: esv
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/esv
esv.tsv: download
download:
ifeq ("$(wildcard ./esv.tsv)","") # Check if the file exists before downloading
ifeq ( $(strip $(unzip -v)), )
curl --location \
--request GET "https://bolls.life/static/translations/ESV.json" \
-o ESV.json
else
curl --location \
--request GET "https://bolls.life/static/translations/ESV.zip" \
-o esv.zip
unzip esv.zip
endif
./convert.py
endif
.PHONY: test clean install uninstall
# end

View File

@ -18,6 +18,6 @@ esv John 3:16
* Credits
Thanks to Luke Smith's kjv project.
I took the awk scripts, makefile, and shell script from him.
I took the awk scripts, Makefile, and shell script from him.
https://github.com/LukeSmithxyz/kjv

176
convert.py Executable file
View File

@ -0,0 +1,176 @@
#!/usr/bin/env python3
import json
import pandas
import re
import os
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('ESV.json')
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("Convertion successful!")