aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2017-08-27 12:11:17 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2017-08-27 12:11:17 +0200
commitba8cb024de435aa92cb3b452a83d29db2fc1e03b (patch)
tree8717aedd2004935df7c812f2ac9b84e1962aa895
parentb72637639be05b8c4a6db2e04070be69a8743cdc (diff)
get_surah_length and get_surah_name methods
-rw-r--r--bismillahbot/quran.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/bismillahbot/quran.py b/bismillahbot/quran.py
index 1efb9e5..1fd323f 100644
--- a/bismillahbot/quran.py
+++ b/bismillahbot/quran.py
@@ -104,8 +104,9 @@ def parse_quran_tafsir():
class Quran:
"""Interface to get ayahs from the Quran."""
- surah_lengths = [0, 7, 286, 200, 176, 120, 165, 206, 75, 129, 109, 123, 111, 43, 52, 99, 128, 111, 110, 98, 135, 112, 78, 118, 64, 77, 227, 93, 88, 69, 60, 34, 30, 73, 54, 45, 83, 182, 88, 75, 85, 54, 53, 89, 59, 37, 35, 38, 29, 18, 45, 60, 49, 62, 55, 78, 96, 29, 22, 24, 13, 14, 11, 11, 18, 12, 12, 30, 52, 52, 44, 28, 28, 20, 56, 40, 31, 50, 40, 46, 42, 29, 19, 36, 25, 22, 17, 19, 26, 30, 20, 15, 21, 11, 8, 8, 19, 5, 8, 8, 11, 11, 8, 3, 9, 5, 4, 7, 3, 6, 3, 5, 4, 5, 6]
- # [0] for normal numbering
+ surah_lengths = (7, 286, 200, 176, 120, 165, 206, 75, 129, 109, 123, 111, 43, 52, 99, 128, 111, 110, 98, 135, 112, 78, 118, 64, 77, 227, 93, 88, 69, 60, 34, 30, 73, 54, 45, 83, 182, 88, 75, 85, 54, 53, 89, 59, 37, 35, 38, 29, 18, 45, 60, 49, 62, 55, 78, 96, 29, 22, 24, 13, 14, 11, 11, 18, 12, 12, 30, 52, 52, 44, 28, 28, 20, 56, 40, 31, 50, 40, 46, 42, 29, 19, 36, 25, 22, 17, 19, 26, 30, 20, 15, 21, 11, 8, 8, 19, 5, 8, 8, 11, 11, 8, 3, 9, 5, 4, 7, 3, 6, 3, 5, 4, 5, 6)
+
+ surah_names = [s.attrib["tname"] for s in ET.parse("quran-data.xml").getroot().find("suras")]
def __init__(self, data: str) -> None:
if data == "arabic":
@@ -130,12 +131,12 @@ class Quran:
@staticmethod
def get_random_ayah() -> Tuple[int, int]:
surah = randint(1, 114)
- ayah = randint(1, Quran.surah_lengths[surah])
+ ayah = randint(1, Quran.get_surah_length(surah))
return surah, ayah
@staticmethod
def get_next_ayah(s: int, a: int) -> Tuple[int, int]:
- length = Quran.surah_lengths[s]
+ length = Quran.get_surah_length(s)
if a == length:
s = s + 1 if s < 114 else 1
a = 1
@@ -147,20 +148,27 @@ class Quran:
def get_previous_ayah(s: int, a: int) -> Tuple[int, int]:
if a == 1:
s = s - 1 if s > 1 else 114
- a = Quran.surah_lengths[s]
+ a = Quran.get_surah_length(s)
else:
a -= 1
return s, a
@staticmethod
def exists(s: int, a: int) -> bool:
- return 0 < s < 115 and 0 < a <= Quran.surah_lengths[s]
+ return 0 < s < 115 and 0 < a <= Quran.get_surah_length(s)
+
+ @staticmethod
+ def get_surah_length(surah: int) -> int:
+ return Quran.surah_lengths[surah - 1]
+
+ @staticmethod
+ def get_surah_name(surah: int) -> str:
+ return Quran.surah_names[surah - 1]
def make_index():
"""An index of the Surahs in the Quran, formatted to send over Telegram."""
- suras = ET.parse("quran-data.xml").getroot().find("suras")
- chapters = [s.attrib["tname"] for s in suras]
+ chapters = Quran.surah_names
# padding...
for i in range(9):
chapters[i] = " " + chapters[i] + " " * (14 - len(chapters[i]))