diff options
| author | Zach DeCook <zachdecook@librem.one> | 2023-07-12 22:57:32 -0400 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2023-07-12 22:57:32 -0400 |
| commit | 447a2efe63dff1bd3fe75ecd4e89521b1eb1e90f (patch) | |
| tree | 71ff45e49fe082ac6d301774e966e57157ac577e | |
| parent | e4edde537c199287636f9db8782b421391eba2d1 (diff) | |
| download | cgi-bin-447a2efe63dff1bd3fe75ecd4e89521b1eb1e90f.tar.gz | |
Bibles: add bsb script
| -rw-r--r-- | .gitignore | 1 | ||||
| -rwxr-xr-x | bsb.py | 55 | ||||
| -rw-r--r-- | getscriptures.sh | 7 |
3 files changed, 63 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 5900037..e786896 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ webp lsv.txt +bsb diff --git a/bsb.py b/bsb.py new file mode 100755 index 0000000..1c63665 --- /dev/null +++ b/bsb.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# pip3 install bible-passage-reference-parser +from bible import parse_string +import usfm2gmi.usfm2gmi as usfm2gmi +import os +import sys +from subprocess import check_output as sco +from webp import printf +from webp import eprint + +def main(qs): + if not qs: + print("10 Enter a scripture reference\r\n") + return + + passages = parse_string(qs) + # TODO: Also handle "john 3, tomato 2" errors? + if type(passages[0]) == tuple: + print("51 " + str(passages[0][0]) + "'\r\n") + return + print("20 text/gemini\r\n") + print('=> https://berean.bible/ This content from Berean Standard Bible (public domain)') + print('=> gemini://gemini.zachdecook.com/usfm2gmi/ and rendered with usfm2gmi') + for passage in passages: + printing = 0 + inendc = False + books=sco(["ls", "bsb/"]).strip().split(b"\n") + fname=b"bsb/"+books[passage.start.book - 1] + print("# " + passage.format()) + f = open(fname) + startc = passage.start.chapter + startv= passage.start.verse + endc = passage.end.chapter + endv= passage.end.verse + for line in f: + if f'\\c {startc}' == line.strip(): + printing = 1 + if startv <= 1: + printing = 2 + if printing == 1 and (f'\\v {startv} ' in line or f'\\v {startv}' == line.strip()): + printing =2 + if (f'\\c {endc}') == line.strip(): + inendc = True + if inendc and (f'\\v {endv+1} ') in line: + printing =0 + if (f'\\c {endc+1}') in line.strip(): + printing =0 + + if printing>=2: + printf(line) + print('(BSB)') #end in newline + +if __name__ == '__main__': + qs = os.getenv("QUERY_STRING") or (sys.argv[1] if len(sys.argv) >= 2 else '') + main(qs) diff --git a/getscriptures.sh b/getscriptures.sh index ec227b2..dcd38e3 100644 --- a/getscriptures.sh +++ b/getscriptures.sh @@ -12,5 +12,12 @@ getlsv() { mv 'The Holy Bible (LSV).txt' lsv.txt rm lsv.zip } +getbsb() { + wget https://bereanbible.com/usfm/bsb_usfm.zip + unzip bsb_usfm.zip + rm bsb_usfm.zip + mv bsb_usfm bsb +} test -d webp || getweb test -f lsv.txt || getlsv +test -d bsb || getbsb |
