scripts for my gemini capsule
oeb: add python script
| -rwxr-xr-x | index.gmi | 2 | ||||
| -rw-r--r-- | makeplan.sh | 2 | ||||
| -rwxr-xr-x | oeb.py | 59 |
3 files changed, 61 insertions, 2 deletions
@@ -6,7 +6,7 @@ printf '20 text/gemini \r\n ## Experimental bible reading scripts => /cgi-bin/esv.sh Wrapper for the English Standard Version API. => /cgi-bin/net.sh Wrapper for New English Translation API. -=> /cgi-bin/oeb.sh Open English Bible (WIP) rough script for reading. +=> /cgi-bin/oeb.py Open English Bible (WIP) rough-ish script for reading. => /cgi-bin/lsv.py Literal Standard Version script for reading. => /cgi-bin/webp.py World English Bible nicer script for reading. diff --git a/makeplan.sh b/makeplan.sh index 4e496ec..29f507e 100644 --- a/makeplan.sh +++ b/makeplan.sh @@ -14,7 +14,7 @@ echo "# New Testament Reading" gmni "gemini://gemini.zachdecook.com/cgi-bin/net.sh?$nt" echo "# Psalm" -gmni "gemini://gemini.zachdecook.com/cgi-bin/oeb.sh?$ps" +gmni "gemini://gemini.zachdecook.com/cgi-bin/oeb.py?$ps" echo "# Proverb" gmni "gemini://gemini.zachdecook.com/cgi-bin/net.sh?$pr" @@ -0,0 +1,59 @@ +#!/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://github.com/openenglishbible/Open-English-Bible This content from OpenEnglishBible (public domain)') + print('=> gemini://gemini.zachdecook.com/usfm2gmi/ and rendered with usfm2gmi') + for passage in passages: + printing = 0 + book=passage.start.format('b').upper() + eprint(book) + fname=sco(['find', 'oeb/', '-iname', f'*-{book}*']).strip() + eprint(fname) + if not fname: + # TODO: throw 51? + print(f"{book} doesn't exist yet in the OEB\r\n") + continue + print("# " + passage.format()) + f = open(fname) + startc = passage.start.chapter + startv= passage.start.verse + endc = passage.end.chapter + endv= passage.end.verse + endmark = passage.end.format('a c:v') + for line in f: + if f'\\c {startc}' == line.strip(): + printing = 1 + if printing == 1 and (f'\\v {startv} ') in line: + printing =2 + if (f'\\c {endc}') == line.strip(): + printing = 3 + if printing == 3 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('(OEB)') #end in newline + +if __name__ == '__main__': + qs = os.getenv("QUERY_STRING") or (sys.argv[1] if len(sys.argv) >= 2 else '') + main(qs) |