aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2017-06-28 19:41:42 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2017-06-28 19:41:42 +0200
commit5bbc166655622aebdd3427ecdcaa0b17898b1c43 (patch)
tree459f7f06eca84fd15934d0c8b0d8f55292ebd573
parentd9d18eaf3eb8e8d59118a63e1f388921dff5a64c (diff)
small code refactor
-rw-r--r--bismillah.py6
-rw-r--r--quran.py24
2 files changed, 16 insertions, 14 deletions
diff --git a/bismillah.py b/bismillah.py
index db344f8..8c3bba2 100644
--- a/bismillah.py
+++ b/bismillah.py
@@ -20,11 +20,11 @@ import sys
from time import sleep, time
import telegram
+import ujson as json
+from redis import StrictRedis
from telegram import InlineQueryResultArticle, InputTextMessageContent
from telegram.constants import MAX_MESSAGE_LENGTH
-from telegram.error import NetworkError, Unauthorized, TelegramError
-from redis import StrictRedis
-import ujson as json
+from telegram.error import NetworkError, TelegramError, Unauthorized
from quran import Quran, make_index
from secret import TOKEN
diff --git a/quran.py b/quran.py
index 71a37ce..483a0f8 100644
--- a/quran.py
+++ b/quran.py
@@ -1,12 +1,10 @@
import re
-from random import randint
import xml.etree.ElementTree as ET
+from random import randint
-def parse_quran_trans():
- """Parse translation text files (with ayah numbers) from
- http://tanzil.net/trans/.
- """
+def parse_quran(filename):
+ """Parse Quran text files (with ayah numbers) from http://tanzil.net."""
quran = []
surah = []
s = 1
@@ -16,10 +14,12 @@ def parse_quran_trans():
return (verse.strip()
.replace("– peace and blessings be upon him", "ﷺ‎"))
- with open("en.ahmedraza", "r") as f:
+ with open(filename, "r") as f:
for line in f.readlines():
- if line == "\n": continue
- if line[:3] == "#==": break
+ if line == "\n":
+ continue
+ if line.startswith("#"):
+ break
verse = line.split("|")
assert len(verse) == 3
if int(verse[0]) == s:
@@ -35,7 +35,7 @@ def parse_quran_trans():
def parse_quran_tafsir():
"""Parse tafsir al-Jalalayn from http://www.altafsir.com/Al-Jalalayn.asp, after
- that PDF was processed with ``pdftotext -nopgbrk Al_Jalalain_Eng.pdf``.
+ that PDF was processed with `pdftotext -nopgbrk Al_Jalalain_Eng.pdf`.
"""
quran = []
surah = []
@@ -92,8 +92,10 @@ class Quran(object):
# [0] for normal numbering
def __init__(self, data):
- if data == "translation":
- self.text = parse_quran_trans()
+ if data == "arabic":
+ self.text = parse_quran("quran-uthmani.txt")
+ elif data == "translation":
+ self.text = parse_quran("en.ahmedraza")
elif data == "tafsir":
self.text = parse_quran_tafsir()