sundays/tools/genbooks.py

630 lines
12 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
use_translations = [
2026-08-14 10:25:59 -06:00
"AAB", # Accessible Ancients Bible AAB
"BSB", # Berean Standard Bible BSB
"ENGWEBP", # World English Bible WEB
"GHT", # Garth's Hyper-literal Translation GHT
"eng_abt", # American Standard Version Byzantine Text ASVBT
"eng_asv", # American Standard Version (1901) ASV
#"eng_bbe", # Bible in Basic English BBE
"eng_boy", # Updated Brenton English Septuagint UBES
"eng_bre", # Brenton Septuagint Translation BST
"eng_emtv", # English Majority Text Version EMTV
#"eng_f35", # The New Testament with Commentary TNTC
"eng_fbv", # Free Bible Version FBV
"eng_glw", # God's Living Word GLW
#"eng_gnv", # Geneva Bible 1599 GNV
"eng_kja", # King James Version + Apocrypha KJVA
"eng_kjv", # King James (Authorized) Version KJAV
"eng_lsv", # Literal Standard Version LSV
"eng_lxx", # LXX2012: Septuagint in American English 2012 LXXSA
"eng_msb", # Majority Standard Bible MSB
"eng_net", # NET Bible NETB
"eng_pev", # Plain English Version PEV
"eng_rv5", # Revised Version with Apocrypha (1895) RVA
"eng_t4t", # Translation for Translators T4T
"eng_tce", # Text-Critical English New Testament TCENT
#"eng_tnt", # Tyndale New Testament TNT
"eng_ulb", # Unlocked Literal Bible ULB
"eng_w88", # Wycliffe Bible W88
"eng_wbs", # Noah Webster Bible NWB
"eng_web", # World English Bible Classic WEBC
"eng_webu", # World English Bible Updated WEBU
"eng_wyc2017", # Wycliffe's Bible with Modern Spelling WBMS
"eng_wyc2018", # Wycliffe's Bible with Modern Spelling (Enhanced) WBMSE
"eng_ylt", # Young's Literal Translation YLT
]
2026-08-17 15:26:55 -06:00
bookmeta = {
2026-08-17 19:43:35 -06:00
'gen': {'tx': 'BSB'},
'exo': {'tx': 'BSB'},
'lev': {'tx': 'BSB'},
'num': {'tx': 'BSB'},
'deu': {'tx': 'BSB'},
'jos': {'tx': 'BSB'},
'jdg': {'tx': 'BSB'},
'rut': {'tx': 'BSB'},
'1sa': {'tx': 'BSB'},
'2sa': {'tx': 'BSB'},
'1ki': {'tx': 'BSB'},
'2ki': {'tx': 'BSB'},
'1ch': {'tx': 'BSB'},
'2ch': {'tx': 'BSB'},
'ezr': {'tx': 'BSB'},
'neh': {'tx': 'BSB'},
'est': {'tx': 'BSB'},
'job': {'tx': 'BSB'},
'psa': {'tx': 'BSB'},
'pro': {'tx': 'BSB'},
'ecc': {'tx': 'BSB'},
'sng': {'tx': 'BSB'},
'isa': {'tx': 'BSB'},
'jer': {'tx': 'BSB'},
'lam': {'tx': 'BSB'},
'ezk': {'tx': 'BSB'},
'dan': {'tx': 'BSB'},
'hos': {'tx': 'BSB'},
'jol': {'tx': 'BSB'},
'amo': {'tx': 'BSB'},
'oba': {'tx': 'BSB'},
'jon': {'tx': 'BSB'},
'mic': {'tx': 'BSB'},
'nam': {'tx': 'BSB'},
'hab': {'tx': 'BSB'},
'zep': {'tx': 'BSB'},
'hag': {'tx': 'BSB'},
'zec': {'tx': 'BSB'},
'mal': {'tx': 'BSB'},
'mat': {'tx': 'BSB'},
'mrk': {'tx': 'BSB'},
'luk': {'tx': 'BSB'},
'jhn': {'tx': 'BSB'},
'act': {'tx': 'BSB'},
'rom': {'tx': 'BSB'},
'1co': {'tx': 'BSB'},
'2co': {'tx': 'BSB'},
'gal': {'tx': 'BSB'},
'eph': {'tx': 'BSB'},
'php': {'tx': 'BSB'},
'col': {'tx': 'BSB'},
'1th': {'tx': 'BSB'},
'2th': {'tx': 'BSB'},
'1ti': {'tx': 'BSB'},
'2ti': {'tx': 'BSB'},
'tit': {'tx': 'BSB'},
'phm': {'tx': 'BSB'},
'heb': {'tx': 'BSB'},
'jas': {'tx': 'BSB'},
'1pe': {'tx': 'BSB'},
'2pe': {'tx': 'BSB'},
'1jn': {'tx': 'BSB'},
'2jn': {'tx': 'BSB'},
'3jn': {'tx': 'BSB'},
'jud': {'tx': 'BSB'},
'rev': {'tx': 'BSB'},
2026-08-17 15:26:55 -06:00
# Apocrypha.
2026-08-17 19:43:35 -06:00
'tob': {'tx': 'eng_lxx'},
'jdt': {'tx': 'eng_lxx'},
'wis': {'tx': 'eng_lxx'},
'sir': {'tx': 'eng_lxx'},
'bar': {'tx': 'eng_lxx'},
'bel': {'tx': 'eng_lxx'},
'sus': {'tx': 'eng_lxx'},
'1ma': {'tx': 'eng_lxx'},
'2ma': {'tx': 'eng_lxx'},
'3ma': {'tx': 'eng_lxx'},
'4ma': {'tx': 'eng_lxx'},
'1es': {'tx': 'eng_lxx'},
2026-08-17 15:26:55 -06:00
# Not present in all LXX.
2026-08-17 19:43:35 -06:00
'lje': {'tx': 'eng_lxx'},
's3y': {'tx': 'eng_lxx'},
'man': {'tx': 'eng_lxx'},
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".encode("utf8"))
if __name__ == "__main__":
2026-08-14 10:25:59 -06:00
pass