scripts for my gemini capsule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/usr/bin/env python3
# pip3 install bible-passage-reference-parser
from bible import parse_string
import xml.etree.ElementTree as ET
from subprocess import check_output as sco
import os
import sys
import usfm2gmi.usx2gmi
from usfm2gmi.usx2gmi import printf
from usfm2gmi.usx2gmi import convertBlock
def main(qs):
passages = parse_string(qs)
print("20 text/gemini\r\n")
for passage in passages:
print("# " + passage.format())
bookNum=passage.start.book
fname=sco(['find', 'asv/', '-name', f'{bookNum}*']).strip()
root = ET.parse(fname).getroot()
printing = 0
endc = False
for thing in list(root):
if thing.tag == 'chapter':
if int(thing.attrib['number']) == int(passage.start.chapter):
printing = 1
if int(thing.attrib['number']) == int(passage.end.chapter):
endc = True
if int(thing.attrib['number']) > int(passage.end.chapter):
printing = 0
if printing >= 1:
printf(convertBlock(thing))
# TODO: check for verses nested elements
if __name__ == '__main__':
qs = os.getenv("QUERY_STRING") or (sys.argv[1] if len(sys.argv) >= 2 else '')
main(qs)
|