Skip to content

Commit

Permalink
v0.1.35; improved commentary output for API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Oct 29, 2024
1 parent 2554adb commit 87b9696
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/
setup(
name=package,
version="0.1.34",
version="0.1.35",
python_requires=">=3.8, <3.13",
description=f"UniqueBible App is a cross-platform & offline bible application, integrated with high-quality resources and unique features. Developers: Eliran Wong and Oliver Tseng",
long_description=long_description,
Expand Down
8 changes: 8 additions & 0 deletions uniquebible/latest_changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
PIP package:

0.1.35

* refine commentary output via api endpoint

0.1.34

* fixed plain text output api endpoint

0.1.32-0.1.33

* Limit api endpoint `/plain` to access private data, only when `private=xxxxxxx` where xxxxxxx matches config.webPrivateHomePage
Expand Down
23 changes: 23 additions & 0 deletions uniquebible/util/RemoteHttpHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from uniquebible.util.TextCommandParser import TextCommandParser
from uniquebible.util.RemoteCliMainWindow import RemoteCliMainWindow
from uniquebible.util.TextUtil import TextUtil
from uniquebible.util.RegexSearch import RegexSearch
from urllib.parse import urlparse, parse_qs
from uniquebible.util.FileUtil import FileUtil
from uniquebible.util.LanguageUtil import LanguageUtil
Expand Down Expand Up @@ -320,6 +321,21 @@ def handleBadRequests(self):
else:
self.blankPage()

def getCommentaryContent(self, chapterCommentary, fullVerseList):
pattern = '(<vid id="v[0-9]+?.[0-9]+?.[0-9]+?"></vid>)<hr>'
searchReplaceItems = ((pattern, r"<hr>\1"),)
chapterCommentary = RegexSearch.deepReplace(chapterCommentary, pattern, searchReplaceItems)
verseCommentaries = chapterCommentary.split("<hr>")

fullVerseList = [f'<vid id="v{b}.{c}.{v}"' for b, c, v, *_ in fullVerseList]

loaded = []
for i in verseCommentaries:
for ii in fullVerseList:
if i.strip() and not i in loaded and ii in i:
loaded.append(i)
return "<hr>".join(loaded)

def do_GET(self):
try:
self.clientIP = self.client_address[0]
Expand All @@ -335,6 +351,7 @@ def do_GET(self):
self.users.append(self.clientIP)
if self.clientIP == self.users[0]:
self.primaryUser = True

# check query
query_components = parse_qs(urlparse(self.path).query)
private = query_components.get("private", [])
Expand All @@ -356,6 +373,12 @@ def do_GET(self):
# output
self.commonHeader()
_, content, _ = self.textCommandParser.parser(self.command, "http")
# refine commentary output
if content and self.command.strip().lower().startswith("commentary:::"):
verseList = self.parser.extractAllReferences(self.command)
if verseList:
fullVerseList = Bible(text="KJV").getEverySingleVerseList(verseList[:1])
content = self.getCommentaryContent(content, fullVerseList)
content = content.replace("<u><b>", "<u><b># ")
plainText = TextUtil.htmlToPlainText(content).strip()
self.wfile.write(bytes(plainText, "utf8"))
Expand Down

0 comments on commit 87b9696

Please sign in to comment.