From a2edc3b8924ace56932709a957774ccb43de9d66 Mon Sep 17 00:00:00 2001
From: tj330
Date: Tue, 2 Jul 2024 09:15:46 +0530
Subject: [PATCH 1/4] Modify notifications.py
---
src/biblenotify/core/notifications.py | 40 ++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/biblenotify/core/notifications.py b/src/biblenotify/core/notifications.py
index dbd8dd2..67bd519 100644
--- a/src/biblenotify/core/notifications.py
+++ b/src/biblenotify/core/notifications.py
@@ -1,5 +1,6 @@
import json
import random
+import re
from PySide6.QtCore import QDateTime, QFile, QObject, QTextStream, QTime, Slot
@@ -76,6 +77,7 @@ def loadVerses(self) -> dict:
verses = json.loads(verses_string)
# Choose a random verse
+ global verse
verse = verses["all"][random.randint(0, len(verses["all"]))]
# TODO: Need to decide on the key names
@@ -96,7 +98,43 @@ def loadChapter(self, location: str) -> dict:
contents_json = json.loads(contents_string)
+ text = self.highlightVerses(contents_json)
+
return {
- "text": contents_json["read"][0]["text"],
+ "text": text,
"place": contents_json["read"][0]["chapter"]
}
+
+ @Slot(str, result="QVariant")
+ def highlightVerses(self, contents_json):
+ # assuming every second verse is preceded by a special delimeter ;
+ # another delimeter should be used since this delimeter have too many edge cases
+ list = re.split(r";", verse["verse"])
+ start = list[0]
+ end = list[-1]
+
+ # to find index of displayed verse from global dictionary {verse} in {contents_json}
+ slice1 = re.search(start, contents_json["read"][0]["text"]).span()
+ slice2 = re.search(end, contents_json["read"][0]["text"]).span()
+
+ to_bold = contents_json["read"][0]["text"][slice1[0] : slice2[1]]
+
+ # in case of two verses
+ if re.search("
\d",to_bold):
+ number = re.findall(r"\d",to_bold)
+
+ split_pattern = r'
\d'
+ separator = '
{}'
+ split_result = re.split(split_pattern, to_bold)
+
+ # joining inorder to get tag inside of
tag and substituting number of second verse
+ formatted_string = separator.join(split_result).format(*number)
+
+ # in case of one verses
+ else:
+ formatted_string = to_bold
+
+
+ text = contents_json["read"][0]["text"].replace(to_bold, "" + formatted_string + "")
+
+ return text
\ No newline at end of file
From d181cb28f6a278c2892119f6178f825272f0a143 Mon Sep 17 00:00:00 2001
From: tj330
Date: Wed, 3 Jul 2024 10:38:44 +0530
Subject: [PATCH 2/4] Add feature
---
src/biblenotify/core/notifications.py | 68 ++++++++++-----------------
1 file changed, 25 insertions(+), 43 deletions(-)
diff --git a/src/biblenotify/core/notifications.py b/src/biblenotify/core/notifications.py
index 67bd519..16eb8c5 100644
--- a/src/biblenotify/core/notifications.py
+++ b/src/biblenotify/core/notifications.py
@@ -9,6 +9,7 @@ class Notifications(QObject):
notificationsEnabled = False
notificationSentLock = False
notificationTime = QDateTime()
+ currentVerse = ''
@Slot(result=bool)
def getNotificationsEnabled(self) -> bool:
@@ -73,18 +74,17 @@ def loadVerses(self) -> dict:
}
contents = QTextStream(file)
- verses_string = contents.readAll()
+ versesString = contents.readAll()
- verses = json.loads(verses_string)
+ verses = json.loads(versesString)
# Choose a random verse
- global verse
- verse = verses["all"][random.randint(0, len(verses["all"]))]
+ self.currentVerse = verses["all"][random.randint(0, len(verses["all"]))]
# TODO: Need to decide on the key names
return {
- "text": verse["verse"],
- "place": verse["place"],
- "location": verse["data"]
+ "text": self.currentVerse["verse"],
+ "place": self.currentVerse["place"],
+ "location": self.currentVerse["data"]
}
@Slot(str, result="QVariant")
@@ -94,47 +94,29 @@ def loadChapter(self, location: str) -> dict:
return ["", ""]
contents = QTextStream(file)
- contents_string = contents.readAll()
+ contentsString = contents.readAll()
- contents_json = json.loads(contents_string)
+ verse = self.currentVerse["verse"]
+ contentsJson = json.loads(contentsString)
- text = self.highlightVerses(contents_json)
+ chapter = contentsJson
+ chapterPlace = chapter["read"][0]["chapter"]
+
+ highlightedChapter = self.highlightVerse(verse, chapter)
return {
- "text": text,
- "place": contents_json["read"][0]["chapter"]
+ "text": highlightedChapter,
+ "place": chapterPlace
}
- @Slot(str, result="QVariant")
- def highlightVerses(self, contents_json):
- # assuming every second verse is preceded by a special delimeter ;
- # another delimeter should be used since this delimeter have too many edge cases
- list = re.split(r";", verse["verse"])
- start = list[0]
- end = list[-1]
-
- # to find index of displayed verse from global dictionary {verse} in {contents_json}
- slice1 = re.search(start, contents_json["read"][0]["text"]).span()
- slice2 = re.search(end, contents_json["read"][0]["text"]).span()
-
- to_bold = contents_json["read"][0]["text"][slice1[0] : slice2[1]]
-
- # in case of two verses
- if re.search("
\d",to_bold):
- number = re.findall(r"\d",to_bold)
-
- split_pattern = r'
\d'
- separator = '
{}'
- split_result = re.split(split_pattern, to_bold)
-
- # joining inorder to get tag inside of
tag and substituting number of second verse
- formatted_string = separator.join(split_result).format(*number)
-
- # in case of one verses
- else:
- formatted_string = to_bold
-
+ def highlightVerse(self, verse, chapter):
+ chapterText = chapter["read"][0]["text"]
+
+ verseMatch = re.search(verse, chapterText)
+ slice = verseMatch.span()
+
+ toHighlight = chapterText[slice[0] : slice[1]]
- text = contents_json["read"][0]["text"].replace(to_bold, "" + formatted_string + "")
+ highlightChapter = chapterText.replace(toHighlight, "" + toHighlight + "")
- return text
\ No newline at end of file
+ return highlightChapter
\ No newline at end of file
From 5a9ea566af944d33ea72baa8799c606b47387575 Mon Sep 17 00:00:00 2001
From: tj330
Date: Wed, 3 Jul 2024 22:32:42 +0530
Subject: [PATCH 3/4] rename variable
---
src/biblenotify/core/notifications.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/biblenotify/core/notifications.py b/src/biblenotify/core/notifications.py
index 16eb8c5..c44b9d8 100644
--- a/src/biblenotify/core/notifications.py
+++ b/src/biblenotify/core/notifications.py
@@ -112,10 +112,10 @@ def loadChapter(self, location: str) -> dict:
def highlightVerse(self, verse, chapter):
chapterText = chapter["read"][0]["text"]
- verseMatch = re.search(verse, chapterText)
- slice = verseMatch.span()
-
- toHighlight = chapterText[slice[0] : slice[1]]
+ verseMatch = re.search(re.escape(verse), chapterText)
+ match = verseMatch.span()
+
+ toHighlight = chapterText[match[0] : match[1]]
highlightChapter = chapterText.replace(toHighlight, "" + toHighlight + "")
From 1b4b5bc627d0c0f3f539866d8780373dd554c6ba Mon Sep 17 00:00:00 2001
From: tj330
Date: Fri, 5 Jul 2024 15:03:08 +0530
Subject: [PATCH 4/4] Add type of parameters
---
src/biblenotify/core/notifications.py | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/biblenotify/core/notifications.py b/src/biblenotify/core/notifications.py
index c44b9d8..4bd4152 100644
--- a/src/biblenotify/core/notifications.py
+++ b/src/biblenotify/core/notifications.py
@@ -9,7 +9,7 @@ class Notifications(QObject):
notificationsEnabled = False
notificationSentLock = False
notificationTime = QDateTime()
- currentVerse = ''
+ currentVerse = ""
@Slot(result=bool)
def getNotificationsEnabled(self) -> bool:
@@ -109,7 +109,7 @@ def loadChapter(self, location: str) -> dict:
"place": chapterPlace
}
- def highlightVerse(self, verse, chapter):
+ def highlightVerse(self, verse: str, chapter: dict) -> str:
chapterText = chapter["read"][0]["text"]
verseMatch = re.search(re.escape(verse), chapterText)
@@ -117,6 +117,7 @@ def highlightVerse(self, verse, chapter):
toHighlight = chapterText[match[0] : match[1]]
- highlightChapter = chapterText.replace(toHighlight, "" + toHighlight + "")
-
- return highlightChapter
\ No newline at end of file
+ highlightedChapter = chapterText.replace(toHighlight, "" + toHighlight + "")
+
+ return highlightedChapter
+
\ No newline at end of file