diff options
authorRahiel Kasim <rahielkasim@gmail.com>2016-08-01 11:25:58 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2016-08-01 11:25:58 +0200
commit2e40da61ac170b13fc9e358de7c5bcd5efbaccdd (patch)
parent9dc266c7cbbf6f23b96eaac9f6212ece50149f90 (diff)
port to python3
3 files changed, 10 insertions, 8 deletions
diff --git a/README.md b/README.md
index 7e4244f..4e73401 100644
--- a/README.md
+++ b/README.md
@@ -28,12 +28,14 @@ You can run your own instance of BismillahBot. First you need to request a
[bot username and token](https://core.telegram.org/bots#3-how-do-i-create-a-bot).
You also need a Unix-like system to run the bot on. BismillahBot is running on a
Debian server. The following gets the code, and installs the dependencies on
+Debian/Ubuntu in a virtualenv:
-sudo apt install redis-server git python-pip python-dev
+sudo apt install redis-server git python3-pip python3-dev virtualenv
git clone https://github.com/rahiel/BismillahBot.git
cd BismillahBot/
+virtualenv -p python3 venv
+. venv/bin/activate
pip install -r requirements.txt
@@ -86,7 +88,8 @@ currently hardcoded in the bot, so
[file an issue](https://github.com/rahiel/BismillahBot/issues/new) if you'd like
to use different data.
-If all went fine you can now run the bot with `python bismillah.py`.
+If all went fine you can now run the bot with `python bismillah.py` in the
## Updating
diff --git a/bismillah.py b/bismillah.py
index 146dcca..85c70df 100644
--- a/bismillah.py
+++ b/bismillah.py
@@ -98,7 +98,7 @@ def serve(bot, data):
elif quran_type in ("english", "tafsir"):
text = data[quran_type].getAyah(s, a)
- bot.sendMessage(chat_id=chat_id, text=text[:4030],
+ bot.sendMessage(chat_id=chat_id, text=text[:telegram.constants.MAX_MESSAGE_LENGTH],
elif quran_type == "arabic":
@@ -147,7 +147,7 @@ def serve(bot, data):
if not update.message: # weird Telegram update with only an update_id
chat_id = update.message.chat_id
- message = update.message.text.encode("utf-8").lower()
+ message = update.message.text.lower()
state = get_user(chat_id)
if state is not None:
s, a, quran_type = state
diff --git a/quran.py b/quran.py
index 090b01b..a34f9da 100755
--- a/quran.py
+++ b/quran.py
@@ -15,8 +15,7 @@ def parse_quran_trans():
def process_verse(verse):
"""Add verse and replace for Arabic ligatures (salawat)"""
return (verse.strip()
- .replace("– peace and blessings be upon him", 'ﷺ‎')
- .decode("utf-8"))
+ .replace("– peace and blessings be upon him", 'ﷺ‎'))
with open("en.ahmedraza", 'r') as f:
for line in f.readlines():
@@ -50,7 +49,7 @@ def parse_quran_tafsir():
def add_line(line, verse):
"""Add line and replace for Arabic ligatures (salawat)"""
- verse.append(line.strip().replace("(s)", 'ﷺ‎').decode("utf-8"))
+ verse.append(line.strip().replace("(s)", 'ﷺ‎'))
with open("Al_Jalalain_Eng.txt", 'r') as f:
for line in f.readlines():