scripts for my gemini capsule
Diffstat (limited to 'hboWLC.py')
| -rwxr-xr-x | hboWLC.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/hboWLC.py b/hboWLC.py new file mode 100755 index 0000000..ecdb9e1 --- /dev/null +++ b/hboWLC.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# pip3 install bible-passage-reference-parser +from bible import parse_string +import usfm2gmi.usfm2gmi as usfm2gmi +import os +import sys +import subprocess +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") + printhboWLC(passages) + +def printhboWLC(passages, title=True, plug=True, printStrongs=False): + books=subprocess.check_output([f"find", "hboWLC/", "-name", f'??-*.usfm']).strip().split(b"\n") + books.sort() + if plug: + print('=>https://ebible.org/find/details.php?id=grctcgnt This content from Westminster Leningrad Codex Hebrew OT (public domain)') + print('=> gemini://gemini.zachdecook.com/usfm2gmi/ and rendered with usfm2gmi') + for passage in passages: + if title: + print("# " + passage.format()) + printing = 0 + inendc = False + bookn = passage.start.book + #eprint(bookn) + if bookn > 66-27: + return + f = open(books[bookn-1]) + startc = passage.start.chapter + startv= passage.start.verse + endc = passage.end.chapter + endv= passage.end.verse + for line in f: + if f'\\c ' in line and f' {startc} ' in line: + printing = 1 + if printing == 1 and (f'\\v {startv} ') in line: + printing =2 + if f'\\c ' in line and f' {endc} ' in line: + inendc = True + if inendc and (f'\\v {endv+1} ') in line: + printing =0 + if f'\\c ' in line and f' {endc+1} ' in line: + printing =0 + + if printing>=2: + printf(line, printStrongs) + print('(hboWLC)') #end in newline + +if __name__ == '__main__': + qs = os.getenv("QUERY_STRING") or (sys.argv[1] if len(sys.argv) >= 2 else '') + main(qs) |