scripts for my gemini capsule
plan: switch to python version of webp script
Zach DeCook 2021-04-10
parent ceb612c · commit 7888e96
-rwxr-xr-xindex.gmi2
-rw-r--r--makeplan.sh2
-rwxr-xr-xwebp.py61
3 files changed, 63 insertions, 2 deletions
diff --git a/index.gmi b/index.gmi
index 66b694b..aa5054a 100755
--- a/index.gmi
+++ b/index.gmi
@@ -8,7 +8,7 @@ printf '20 text/gemini \r\n
=> /cgi-bin/net.sh Wrapper for New English Translation API.
=> /cgi-bin/oeb.sh Open English Bible (WIP) rough script for reading.
=> /cgi-bin/lsv.py Literal Standard Version script for reading.
-=> /cgi-bin/webp.sh World English Bible rough script for reading.
+=> /cgi-bin/webp.py World English Bible nicer script for reading.
## misc
=> /cgi-bin/ccel.sh ccel.org frontend
diff --git a/makeplan.sh b/makeplan.sh
index 4bb53e0..4e496ec 100644
--- a/makeplan.sh
+++ b/makeplan.sh
@@ -8,7 +8,7 @@ ps="$(grep "^$day" "$1" | cut -f4)"
pr="$(grep "^$day" "$1" | cut -f5)"
echo "# Old Testament Reading"
-gmni "gemini://gemini.zachdecook.com/cgi-bin/webp.sh?$ot"
+gmni "gemini://gemini.zachdecook.com/cgi-bin/webp.py?$ot"
echo "# New Testament Reading"
gmni "gemini://gemini.zachdecook.com/cgi-bin/net.sh?$nt"
diff --git a/webp.py b/webp.py
new file mode 100755
index 0000000..b747d0d
--- /dev/null
+++ b/webp.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
+
+def printf(line):
+ if line.strip():
+ print(usfm2gmi.convert(line), end=' ')
+ else:
+ print()
+
+def eprint(*args, **kwargs):
+ print(*args, file=sys.stderr, **kwargs)
+
+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://ebible.org/find/details.php?id=engwebp&all=1 This content from World English Bible (public domain)')
+ print('=> gemini://gemini.zachdecook.com/usfm2gmi/ and rendered with usfm2gmi')
+ for passage in passages:
+ print("# " + passage.format())
+ printing = 0
+ bookabbrev=passage.start.format('a').upper()
+ fname = subprocess.check_output([f"find", "webp/", "-name", f'*-{bookabbrev}*']).strip()
+ eprint(fname)
+ 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} ' in line:
+ printing = 1
+ if printing == 1 and (f'\\v {startv} ') in line:
+ printing =2
+ if (f'\\c {endc} ') in line:
+ printing = 3
+ if printing == 3 and (f'\\v {endv+1} ') in line:
+ printing =0
+ if (f'\\c {endc+1} ') in line:
+ printing =0
+
+ if printing>=2:
+ printf(line)
+ print('(WEB)') #end in newline
+
+if __name__ == '__main__':
+ qs = os.getenv("QUERY_STRING") or (sys.argv[1] if len(sys.argv) >= 2 else '')
+ main(qs)