aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahiel@protonmail.ch>2015-11-20 14:35:10 +0100
committerRahiel Kasim <rahiel@protonmail.ch>2015-11-20 14:35:10 +0100
commitc70b06f1c87396e3822ae89ca095f252e1a98d71 (patch)
tree6259e0ed5b3a7619aaecb4c4c7e38f3f9992f13d
parentd8aacd9a5b8a095cef1244c2a97af2333fc3da3b (diff)
handle "Unauthorized" exception
-rw-r--r--bismillah.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/bismillah.py b/bismillah.py
index 9ea8fee..f95b505 100644
--- a/bismillah.py
+++ b/bismillah.py
@@ -60,7 +60,13 @@ def get_file(filename):
def main():
bot = telegram.Bot(token=TOKEN)
- update_id = None
+
+ # get the first pending update_id, this is so we can skip over it in case
+ # we get an "Unauthorized" exception.
+ try:
+ update_id = bot.getUpdates()[0].update_id
+ except IndexError:
+ update_id = None
data = {"english": english, "tafsir": tafsir}
@@ -70,6 +76,8 @@ def main():
except telegram.TelegramError as e:
if e.message in ("Bad Gateway", "Timed out"):
sleep(3)
+ elif e.message == "Unauthorized":
+ update_id += 1
else:
raise e
except URLError as e: