aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahiel@protonmail.ch>2015-11-19 09:56:50 +0100
committerRahiel Kasim <rahiel@protonmail.ch>2015-11-19 09:56:50 +0100
commitd8aacd9a5b8a095cef1244c2a97af2333fc3da3b (patch)
tree8acc48127cf0dca6f570e5aa47fa19ecfe7feba2
parent1d792532326b5b6fcd72b2051a5a2b2ea44af111 (diff)
better logging, docstrings and json to file function
-rw-r--r--bismillah.py2
-rwxr-xr-xquran.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/bismillah.py b/bismillah.py
index 144d000..9ea8fee 100644
--- a/bismillah.py
+++ b/bismillah.py
@@ -141,7 +141,7 @@ def serve(bot, update_id, data):
else:
s, a, quran_type = 1, 1, "english"
- print message
+ print("%d: %s" % (chat_id, message))
if chat_id < 0:
continue # bot should not be in a group
diff --git a/quran.py b/quran.py
index f54c830..81df2b5 100755
--- a/quran.py
+++ b/quran.py
@@ -4,6 +4,9 @@ from random import randint
def parse_quran_trans():
+ """Parse translation text files (with ayah numbers) from
+ http://tanzil.net/trans/.
+ """
quran = []
surah = []
s = 1
@@ -31,6 +34,9 @@ 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``.
+ """
quran = []
surah = []
s, v = 1, 1
@@ -81,6 +87,7 @@ def parse_quran_tafsir():
class Quran(object):
+ """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
@@ -126,3 +133,11 @@ class Quran(object):
else:
a -= 1
return s, a
+
+
+def save_json(quran):
+ """Save Quran to a json file."""
+ import json
+
+ with open("quran.json", 'w') as f:
+ json.dump(quran, f, ensure_ascii=False)