From 381f7cdcfc0c671f169d72df74c8256bc5bca70e Mon Sep 17 00:00:00 2001 From: Judah Date: Mon, 4 Mar 2024 17:20:06 -0500 Subject: [PATCH] First code --- add-booknames.py | 273 +++++++++++++++++++++++++++++++++++++++++++++++ json-to-tsv.py | 17 +++ 2 files changed, 290 insertions(+) create mode 100755 add-booknames.py create mode 100755 json-to-tsv.py diff --git a/add-booknames.py b/add-booknames.py new file mode 100755 index 0000000..83643b9 --- /dev/null +++ b/add-booknames.py @@ -0,0 +1,273 @@ +#!/usr/bin/env python3 +import re +f = open('esv.tsv', 'r') +outfile = open('esv-correct.tsv', 'w') +testfile = open('test.tsv', 'w') +for item in f: + + number = re.search('[0-9]+', item).group() + + match number: + case "1": + testfile.write(item) + outfile.write("Genesis Ge\t" + item) + + case "2": + testfile.write(item) + outfile.write("Exodus Exo\t" + item) + + case "3": + testfile.write(item) + outfile.write("Leviticus Lev\t" + item) + + case "4": + testfile.write(item) + outfile.write("Numbers Num\t" + item) + + case "5": + testfile.write(item) + outfile.write("Deuteronomy Deu\t" + item) + + case "6": + testfile.write(item) + outfile.write("Joshua Josh\t" + item) + + case "7": + testfile.write(item) + outfile.write("Judges Jdgs\t" + item) + + case "8": + testfile.write(item) + outfile.write("Ruth Ruth\t" + item) + + case "9": + testfile.write(item) + outfile.write("1 Samuel 1Sm\t" + item) + + case "10": + testfile.write(item) + outfile.write("2 Samuel 2Sm\t" + item) + + case "11": + testfile.write(item) + outfile.write("1 Kings 1Ki\t" + item) + + case "12": + testfile.write(item) + outfile.write("2 Kings 2Ki\t" + item) + + case "13": + testfile.write(item) + outfile.write("1 Chronicles 1Chr\t" + item) + + case "14": + testfile.write(item) + outfile.write("2 Chronicles 2Chr\t" + item) + + case "15": + testfile.write(item) + outfile.write("Ezra Ezra\t" + item) + + case "16": + outfile.write("Nehemiah Neh\t" + item) + testfile.write(item) + + case "17": + testfile.write(item) + outfile.write("Esther Est\t" + item) + + case "18": + testfile.write(item) + outfile.write("Job Job\t" + item) + + case "19": + testfile.write(item) + outfile.write("Psalms Psa\t" + item) + + case "20": + testfile.write(item) + outfile.write("Proverbs Prv\t" + item) + + case "21": + testfile.write(item) + outfile.write("Ecclesiastes Eccl\t" + item) + + case "22": + testfile.write(item) + outfile.write("Song of Solomon SSol\t" + item) + + case "23": + testfile.write(item) + outfile.write("Isaiah Isa\t" + item) + + case "24": + testfile.write(item) + outfile.write("Jeremiah Jer\t" + item) + + case "25": + testfile.write(item) + outfile.write("Lamentations Lam\t" + item) + + case "26": + testfile.write(item) + outfile.write("Ezekiel Eze\t" + item) + + case "27": + testfile.write(item) + outfile.write("Daniel Dan\t" + item) + + case "28": + testfile.write(item) + outfile.write("Hosea Hos\t" + item) + + case "29": + testfile.write(item) + outfile.write("Joel Joel\t" + item) + + case "30": + testfile.write(item) + outfile.write("Amos Amos\t" + item) + + case "31": + testfile.write(item) + outfile.write("Obadiah Obad\t" + item) + + case "32": + testfile.write(item) + outfile.write("Jonah Jonah\t" + item) + + case "33": + testfile.write(item) + outfile.write("Micah Mic\t" + item) + + case "34": + testfile.write(item) + outfile.write("Nahum Nahum\t" + item) + + case "35": + testfile.write(item) + outfile.write("Habakkuk Hab\t" + item) + + case "36": + testfile.write(item) + outfile.write("Zephaniah Zep\t" + item) + + case "37": + testfile.write(item) + outfile.write("Haggai Hag\t" + item) + + case "38": + testfile.write(item) + outfile.write("Zechariah Zec\t" + item) + + case "39": + testfile.write(item) + outfile.write("Malachi Mal\t" + item) + + case "40": + testfile.write(item) + outfile.write("Matthew Mat\t" + item) + + case "41": + testfile.write(item) + outfile.write("Mark Mark\t" + item) + + case "42": + testfile.write(item) + outfile.write("Luke Luke\t" + item) + + case "43": + testfile.write(item) + outfile.write("John John\t" + item) + + case "44": + testfile.write(item) + outfile.write("The Acts Acts\t" + item) + + case "45": + testfile.write(item) + outfile.write("Romans Rom\t" + item) + + case "46": + testfile.write(item) + outfile.write("1 Corinthians 1Cor\t" + item) + + case "47": + testfile.write(item) + outfile.write("2 Corinthians 2Cor\t" + item) + + case "48": + testfile.write(item) + outfile.write("Galatians Gal\t" + item) + + case "49": + testfile.write(item) + outfile.write("Ephesians Eph\t" + item) + + case "50": + testfile.write(item) + outfile.write("Philippians Phi\t" + item) + + case "51": + testfile.write(item) + outfile.write("Colossians Col\t" + item) + + case "52": + testfile.write(item) + outfile.write("1 Thessalonians 1Th\t" + item) + + case "53": + testfile.write(item) + outfile.write("2 Thessalonians 2Th\t" + item) + + case "54": + testfile.write(item) + outfile.write("1 Timothy 1Tim\t" + item) + + case "55": + testfile.write(item) + outfile.write("2 Timothy 2Tim\t" + item) + + case "56": + testfile.write(item) + outfile.write("Titus Titus\t" + item) + + case "57": + testfile.write(item) + outfile.write("Philemon Phmn\t" + item) + + case "58": + testfile.write(item) + outfile.write("Hebrews Heb\t" + item) + + case "59": + testfile.write(item) + outfile.write("James Jas\t" + item) + + case "60": + testfile.write(item) + outfile.write("1 Peter 1Pet\t" + item) + + case "61": + testfile.write(item) + outfile.write("2 Peter 2Pet\t" + item) + + case "62": + testfile.write(item) + outfile.write("1 John 1Jn\t" + item) + + case "63": + testfile.write(item) + outfile.write("2 John 2Jn\t" + item) + + case "64": + testfile.write(item) + outfile.write("3 John 3Jn\t" + item) + + case "65": + testfile.write(item) + outfile.write("Jude Jude\t" + item) + + case "66": + testfile.write(item) + outfile.write("Revelation Rev\t" + item) diff --git a/json-to-tsv.py b/json-to-tsv.py new file mode 100755 index 0000000..5065115 --- /dev/null +++ b/json-to-tsv.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import json +import pandas +from flatten_json import flatten + +f = open('ESV.json') + +json_list = json.load(f) +key_list = ['book', 'chapter', 'verse', 'text'] +json_list = [{k:d[k] for k in key_list} for d in json_list] + +# Flatten and convert to a data frame +json_list_flattened = (flatten(d, '.') for d in json_list) +df = pandas.DataFrame(json_list_flattened) + +export_csv = df.to_csv('esv.tsv', sep='\t', encoding='utf-8', index=None, header=True)