#!/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!")