notes/tools/genbooks.py

648 lines
14 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import json
import requests
2026-08-14 15:26:52 -06:00
alias_map = {
2026-08-17 19:43:35 -06:00
"gen": [
"Genesis",
"gn"
],
"exo": [
"Exodus",
"ex"
],
"lev": [
"Leviticus",
"lv"
],
"num": [
"Numbers",
"nm",
"numb",
"nmb",
"nmbs"
],
"deu": [
"Deuteronomy",
"dt",
"deut",
"deuter"
],
"jos": [
"Joshua",
"js",
"josh"
],
"jdg": [
"Judges",
"jd",
"jdgs"
],
"rut": [
"Ruth",
"rt"
],
"1sa": [
"1 Samuel",
"1s",
"1sam",
"1 s",
"1 sa",
"1 sam",
"1 Kingdoms",
"1 Realms"
],
"2sa": [
"2 Samuel",
"2s",
"2sam",
"2 s",
"2 sa",
"2 sam",
"2 Kingdoms",
"2 Realms"
],
"1ki": [
"1 Kings",
"1k",
"1kgs",
"1king",
"1 k",
"1 ki",
"1 kgs",
"1 king",
"3k",
"3kgs",
"3king",
"3 k",
"3 ki",
"3 kgs",
"3 king",
"3 Kingdoms",
"3 Realms"
],
"2ki": [
"2 Kings",
"2k",
"2kgs",
"2king",
"2 k",
"2 ki",
"2 kgs",
"2 king",
"4k",
"4kgs",
"4king",
"4 k",
"4 ki",
"4 kgs",
"4 king",
"4 Kingdoms",
"4 Realms"
],
"1ch": [
"1 Chronicles",
"1c",
"1chr",
"1chron",
"1 c",
"1 ch",
"1 chr",
"1 chron"
],
"2ch": [
"2 Chronicles",
"2c",
"2chr",
"2chron",
"2 c",
"2 ch",
"2 chr",
"2 chron"
],
"ezr": [
"Ezra",
"ez"
],
"neh": [
"Nehemiah",
"nh"
],
"est": [
"Esther",
"es"
],
"job": [
"Job",
"jb"
],
"psa": [
"Psalms",
"ps",
"psalm",
"pss"
],
"pro": [
"Proverbs",
"pr",
"prov"
],
"ecc": [
"Ecclesiastes",
"ec",
"eccl",
"eccle"
],
"sng": [
"Song of Solomon",
"song of songs",
"sn",
"son",
"song",
"sol"
],
"isa": [
"Isaiah",
"is",
"isai"
],
"jer": [
"Jeremiah",
"jr",
"jere",
"jerem"
],
"lam": [
"Lamentations",
"lm",
"lamen"
],
"ezk": [
"Ezekiel",
"eze",
"ezek"
],
"dan": [
"Daniel",
"dn"
],
"hos": [
"Hosea",
"hs"
],
"jol": [
"Joel",
"jl"
],
"amo": [
"Amos",
"am"
],
"oba": [
"Obadiah",
"ob",
"obd",
"obad"
],
"jon": [
"Jonah",
"jo"
],
"mic": [
"Micah",
"micha",
"mc"
],
"nam": [
"Nahum",
"na"
],
"hab": [
"Habakkuk",
"hb",
"haba",
"habak"
],
"zep": [
"Zephaniah",
"zf",
"zef"
],
"hag": [
"Haggai",
"hg"
],
"zec": [
"Zechariah",
"ze",
"zech"
],
"mal": [
"Malachi",
"ml",
"mala"
],
"mat": [
"Matthew",
"mt",
"matt"
],
"mrk": [
"Mark",
"mk"
],
"luk": [
"Luke",
"lk"
],
"jhn": [
"John",
"jn"
],
"act": [
"Acts",
"ac"
],
"rom": [
"Romans",
"rm",
"rms"
],
"1co": [
"1 Corinthians",
"1cor",
"1corin",
"1 co",
"1 cor",
"1 corin"
],
"2co": [
"2 Corinthians",
"2cor",
"2corin",
"2 co",
"2 cor",
"2 corin"
],
"gal": [
"Galatians",
"gl"
],
"eph": [
"Ephesians",
"ep",
"ef"
],
"php": [
"Philippians",
"ph",
"phil"
],
"col": [
"Colossians",
"cl",
"colo"
],
"1th": [
"1 Thessalonians",
"1thes",
"1thess",
"1 thes",
"1 thess"
],
"2th": [
"2 Thessalonians",
"2thes",
"2thess",
"2 thes",
"2 thess"
],
"1ti": [
"1 Timothy",
"1tim",
"1 ti",
"1 tim"
],
"2ti": [
"2 Timothy",
"2tim",
"2 ti",
"2 tim"
],
"tit": [
"Titus",
"ti"
],
"phm": [
"Philemon",
"pi",
"philm",
"philem"
],
"heb": [
"Hebrews",
"he"
],
"jas": [
"James",
"ja",
"jam"
],
"1pe": [
"1 Peter",
"1p",
"1pt",
"1pet",
"1 p",
"1 pe",
"1 pt",
"1 pet"
],
"2pe": [
"2 Peter",
"2p",
"2pt",
"2pet",
"2 p",
"2 pe",
"2 pt",
"2 pet"
],
"1jn": [
"1 John",
"1jon",
"1 jn",
"1 jon"
],
"2jn": [
"2 John",
"2jon",
"2 jn",
"2 jon"
],
"3jn": [
"3 John",
"3jon",
"3 jn",
"3 jon"
],
"jud": [
"Jude",
"ju"
],
"rev": [
"Revelation",
"rv",
"reve"
],
"tob": [
"Tobit",
"tb"
],
"jdt": [
"Judith",
"jt"
],
"wis": [
"Wisdom",
"wisdom of solomon",
"ws",
"wos"
],
"sir": [
"Sirach",
"sr"
],
"bar": [
"Baruch",
"br"
],
"bel": [
"Bel and the Dragon",
"bl",
"bd",
"batd"
],
"sus": [
"Susanna",
"su"
],
"1ma": [
"1 Maccabees",
"1mac",
"1 mac"
],
"2ma": [
"2 Maccabees",
"2mac",
"2 mac"
],
"3ma": [
"3 Maccabees",
"3mac",
"3 mac"
],
"4ma": [
"4 Maccabees",
"4mac",
"4 mac"
],
"1es": [
"1 Esdras",
"1esd",
"1 esd"
],
"lje": [
"Epistle of Jeremy",
"ej",
"eoj"
],
"s3y": [
"Prayer of Ezarias",
"az",
"poe"
],
"man": [
"Prayer of Manasses",
"prayer of manasseh",
"mana",
"pom"
]
2026-08-14 15:26:52 -06:00
}
2026-08-17 19:43:35 -06:00
aliases = {i.lower(): k for k, v in alias_map.items() for i in v}
2026-08-14 15:26:52 -06:00
for k in alias_map.keys():
aliases[k] = k
shorthand_defaults = {
"OT": "BSB",
"NT": "BSB",
"APO": "eng_kja",
"LXX": "eng_lxx",
}
2026-08-18 15:23:04 -06:00
use_translations = {
"BSB": ["Berean Standard Bible", "BSB", ["OT", "NT"]],
"eng_msb": ["Majority Standard Bible", "MSB", ["NT"]],
"eng_lsv": ["Literal Standard Version", "LSV", ["OT", "NT"]],
"eng_net": ["NET Bible", "NETB", ["OT", "NT"]],
"eng_asv": ["American Standard Version (1901)", "ASV", ["OT", "NT"]],
"eng_abt": ["American Standard Version Byzantine Text", "ASVBT", ["OT", "NT"]],
"eng_kjv": ["King James (Authorized) Version", "KJAV", ["OT", "NT"]],
"eng_kja": ["King James Version + Apocrypha", "KJVA", ["OT", "NT", "APO"]],
"eng_rv5": ["Revised Version with Apocrypha (1895)", "RVA", ["OT", "NT", "APO"]],
"eng_ylt": ["Young's Literal Translation", "YLT", ["OT", "NT"]],
"AAB": ["Accessible Ancients Bible", "AAB", ["OT", "NT"]],
"eng_fbv": ["Free Bible Version", "FBV", ["OT", "NT"]],
"eng_wbs": ["Noah Webster Bible", "NWB", ["OT", "NT"]],
2026-08-19 15:35:25 -06:00
"eng_t4t": ["Translation for Translators", "T4T", ["OT", "NT"]],
# Parser: Spacing issues. Matthew 16:13.
# Footnotes may need to be implemented.
# See: /sundays/notes/2026/07/19/
#"eng_tce": ["Text-Critical English New Testament", "TCENT", ["NT"]],
"eng_ulb": ["Unlocked Literal Bible", "ULB", ["OT", "NT"]],
"ENGWEBP": ["World English Bible", "WEB", ["OT", "NT"]],
"eng_web": ["World English Bible Classic", "WEBC", ["OT", "NT"]],
"eng_webu": ["World English Bible Updated", "WEBU", ["OT", "NT"]],
"eng_lxx": ["Septuagint in American English (2012)", "LXXSA", ["OT", "APO"]],
"eng_bre": ["Brenton Septuagint Translation", "BST", ["OT", "APO"]],
"eng_boy": ["Updated Brenton English Septuagint", "UBES", ["OT", "APO"]],
2026-08-19 15:35:25 -06:00
# May be too literal and difficult to read.
#"GHT": ["Garth's Hyper-literal Translation", "GHT", ["NT"]],
2026-08-17 21:38:21 -06:00
#"eng_bbe": ["Bible in Basic English BBE"],
# Broken: Parser?
2026-08-19 15:35:25 -06:00
"eng_emtv": ["English Majority Text Version", "EMTV", ["NT"]],
# Mostly useful if footnotes are implemented in the parser.
#"eng_f35": ["The New Testament with Commentary", "TNTC", ["NT"]],
# Broken: Parser?
2026-08-19 15:35:25 -06:00
"eng_glw": ["God's Living Word", "GLW", ["OT", "NT"]],
2026-08-17 21:38:21 -06:00
#"eng_gnv": ["Geneva Bible 1599 GNV"],
# Broken: Reads like heresy.
2026-08-19 15:35:25 -06:00
#"eng_pev": ["Plain English Version", "PEV", ["OT", "NT"]],
# Broken: Empty content.
2026-08-19 15:35:25 -06:00
# Archaic English.
#"eng_tnt": ["Tyndale New Testament TNT", "TNT", ["NT"]],
2026-08-18 20:59:33 -06:00
#"eng_w88": ["Wycliffe Bible", "W88"],
#"eng_wyc2017": ["Wycliffe's Bible with Modern Spelling", "WBMS"],
2026-08-19 15:35:25 -06:00
"eng_wyc2018": ["Wycliffe's Bible with Modern Spelling", "WBMSE", ["OT", "NT"]],
2026-08-18 15:23:04 -06:00
}
2026-08-17 15:26:55 -06:00
bookmeta = {
'gen': {'tx': 'BSB', 'ts': 'OT'},
'exo': {'tx': 'BSB', 'ts': 'OT'},
'lev': {'tx': 'BSB', 'ts': 'OT'},
'num': {'tx': 'BSB', 'ts': 'OT'},
'deu': {'tx': 'BSB', 'ts': 'OT'},
'jos': {'tx': 'BSB', 'ts': 'OT'},
'jdg': {'tx': 'BSB', 'ts': 'OT'},
'rut': {'tx': 'BSB', 'ts': 'OT'},
'1sa': {'tx': 'BSB', 'ts': 'OT'},
'2sa': {'tx': 'BSB', 'ts': 'OT'},
'1ki': {'tx': 'BSB', 'ts': 'OT'},
'2ki': {'tx': 'BSB', 'ts': 'OT'},
'1ch': {'tx': 'BSB', 'ts': 'OT'},
'2ch': {'tx': 'BSB', 'ts': 'OT'},
'ezr': {'tx': 'BSB', 'ts': 'OT'},
'neh': {'tx': 'BSB', 'ts': 'OT'},
'est': {'tx': 'BSB', 'ts': 'OT'},
'job': {'tx': 'BSB', 'ts': 'OT'},
'psa': {'tx': 'BSB', 'ts': 'OT'},
'pro': {'tx': 'BSB', 'ts': 'OT'},
'ecc': {'tx': 'BSB', 'ts': 'OT'},
'sng': {'tx': 'BSB', 'ts': 'OT'},
'isa': {'tx': 'BSB', 'ts': 'OT'},
'jer': {'tx': 'BSB', 'ts': 'OT'},
'lam': {'tx': 'BSB', 'ts': 'OT'},
'ezk': {'tx': 'BSB', 'ts': 'OT'},
'dan': {'tx': 'BSB', 'ts': 'OT'},
'hos': {'tx': 'BSB', 'ts': 'OT'},
'jol': {'tx': 'BSB', 'ts': 'OT'},
'amo': {'tx': 'BSB', 'ts': 'OT'},
'oba': {'tx': 'BSB', 'ts': 'OT'},
'jon': {'tx': 'BSB', 'ts': 'OT'},
'mic': {'tx': 'BSB', 'ts': 'OT'},
'nam': {'tx': 'BSB', 'ts': 'OT'},
'hab': {'tx': 'BSB', 'ts': 'OT'},
'zep': {'tx': 'BSB', 'ts': 'OT'},
'hag': {'tx': 'BSB', 'ts': 'OT'},
'zec': {'tx': 'BSB', 'ts': 'OT'},
'mal': {'tx': 'BSB', 'ts': 'OT'},
'mat': {'tx': 'BSB', 'ts': 'NT'},
'mrk': {'tx': 'BSB', 'ts': 'NT'},
'luk': {'tx': 'BSB', 'ts': 'NT'},
'jhn': {'tx': 'BSB', 'ts': 'NT'},
'act': {'tx': 'BSB', 'ts': 'NT'},
'rom': {'tx': 'BSB', 'ts': 'NT'},
'1co': {'tx': 'BSB', 'ts': 'NT'},
'2co': {'tx': 'BSB', 'ts': 'NT'},
'gal': {'tx': 'BSB', 'ts': 'NT'},
'eph': {'tx': 'BSB', 'ts': 'NT'},
'php': {'tx': 'BSB', 'ts': 'NT'},
'col': {'tx': 'BSB', 'ts': 'NT'},
'1th': {'tx': 'BSB', 'ts': 'NT'},
'2th': {'tx': 'BSB', 'ts': 'NT'},
'1ti': {'tx': 'BSB', 'ts': 'NT'},
'2ti': {'tx': 'BSB', 'ts': 'NT'},
'tit': {'tx': 'BSB', 'ts': 'NT'},
'phm': {'tx': 'BSB', 'ts': 'NT'},
'heb': {'tx': 'BSB', 'ts': 'NT'},
'jas': {'tx': 'BSB', 'ts': 'NT'},
'1pe': {'tx': 'BSB', 'ts': 'NT'},
'2pe': {'tx': 'BSB', 'ts': 'NT'},
'1jn': {'tx': 'BSB', 'ts': 'NT'},
'2jn': {'tx': 'BSB', 'ts': 'NT'},
'3jn': {'tx': 'BSB', 'ts': 'NT'},
'jud': {'tx': 'BSB', 'ts': 'NT'},
'rev': {'tx': 'BSB', 'ts': 'NT'},
2026-08-17 15:26:55 -06:00
# Apocrypha.
'tob': {'tx': 'eng_lxx', 'ts': 'APO'},
'jdt': {'tx': 'eng_lxx', 'ts': 'APO'},
'wis': {'tx': 'eng_lxx', 'ts': 'APO'},
'sir': {'tx': 'eng_lxx', 'ts': 'APO'},
'bar': {'tx': 'eng_lxx', 'ts': 'APO'},
'bel': {'tx': 'eng_lxx', 'ts': 'APO'},
'sus': {'tx': 'eng_lxx', 'ts': 'APO'},
'1ma': {'tx': 'eng_lxx', 'ts': 'APO'},
'2ma': {'tx': 'eng_lxx', 'ts': 'APO'},
'3ma': {'tx': 'eng_lxx', 'ts': 'APO'},
'4ma': {'tx': 'eng_lxx', 'ts': 'APO'},
'1es': {'tx': 'eng_lxx', 'ts': 'APO'},
2026-08-17 15:26:55 -06:00
# Not present in all LXX.
'lje': {'tx': 'eng_lxx', 'ts': 'APO'},
's3y': {'tx': 'eng_lxx', 'ts': 'APO'},
'man': {'tx': 'eng_lxx', 'ts': 'APO'},
2026-08-17 15:26:55 -06:00
}
2026-08-17 19:43:35 -06:00
for k, v in bookmeta.items():
if k in alias_map:
v["title"] = alias_map[k][0]
2026-08-17 15:26:55 -06:00
def get_translations():
req = requests.get("https://bible.helloao.org/api/available_translations.json")
2026-08-14 10:25:59 -06:00
t = req.json()
return [x for x in filter(lambda x: "language" in x and x["language"] == "eng", t["translations"])]
2026-08-14 10:25:59 -06:00
def filter_translations(t=None):
tx = []
if t is None:
t = get_translations()
for translation in t:
if "id" in translation and translation["id"] in use_translations:
tx.append(translation)
2026-08-14 15:26:52 -06:00
return {x["id"]: x for x in tx}
2026-08-14 10:25:59 -06:00
def get_translation_meta(t):
2026-08-14 15:26:52 -06:00
req = requests.get(f"https://bible.helloao.org{t["listOfBooksApiLink"]}")
return req.json()
def write_meta(file="meta.js"):
with open(file, 'wb') as fp:
fp.write(b"// Translation meta\n\n")
fp.write(f"export const aliases = {json.dumps(aliases)};\n\n".encode("utf8"))
2026-08-17 15:26:55 -06:00
fp.write(f"export const translations = {json.dumps(use_translations)};\n\n".encode("utf8"))
fp.write(f"export const meta = {json.dumps(bookmeta)};\n\n".encode("utf8"))
fp.write(f"export const defaulttx = {json.dumps(shorthand_defaults)};\n\n".encode("utf8"))
if __name__ == "__main__":
2026-08-14 10:25:59 -06:00
pass