From fc86a09bbf86643d930f3011cae1fc7a8b79bbab Mon Sep 17 00:00:00 2001 From: Judah Date: Mon, 4 Mar 2024 21:19:45 -0500 Subject: [PATCH] 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. --- .gitignore | 3 + Makefile | 21 ++++++- README.org | 2 +- convert.py | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+), 2 deletions(-) create mode 100755 convert.py diff --git a/.gitignore b/.gitignore index 8c9204a..84a6bcf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ esv +ESV.json +esv.tsv +esv.zip diff --git a/Makefile b/Makefile index b5bfde2..78358f9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.org b/README.org index 5ec2d9d..356c75b 100644 --- a/README.org +++ b/README.org @@ -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 diff --git a/convert.py b/convert.py new file mode 100755 index 0000000..8c1889e --- /dev/null +++ b/convert.py @@ -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!")