From 8bde310ec7254613d580a8fba5fa2a992ce17cd2 Mon Sep 17 00:00:00 2001 From: Francisco Demartino Date: Tue, 17 Nov 2015 01:34:00 -0300 Subject: [PATCH 1/2] README: add link to TwitterForwarderBot --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index ed7768bfc..d44ea2caa 100644 --- a/README.rst +++ b/README.rst @@ -261,6 +261,8 @@ Here follows some examples to help you to get your own Bot up to speed: - `DevOps Reaction Bot `_ sends latest or random posts from `DevOps Reaction `_. Running on `Google App Engine `_ (billing has to be enabled for fully Socket API support). +- `TwitterForwarderBot `_ forwards you tweets from people that you have subscribed to. + ================ _`Documentation` ================ From 62b79df0a4269aebd6720882c851650af908076c Mon Sep 17 00:00:00 2001 From: Rahiel Kasim Date: Fri, 20 Nov 2015 14:41:12 +0100 Subject: [PATCH 2/2] handle "Unauthorized" exceptions in echobot --- examples/echobot.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/echobot.py b/examples/echobot.py index 949b0255a..3f65441ac 100644 --- a/examples/echobot.py +++ b/examples/echobot.py @@ -29,14 +29,19 @@ except ImportError: def main(): - update_id = None + # Telegram Bot Authorization Token + bot = telegram.Bot('TOKEN') + + # 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 logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') - # Telegram Bot Authorization Token - bot = telegram.Bot('TOKEN') - while True: try: update_id = echo(bot, update_id) @@ -44,6 +49,9 @@ def main(): # These are network problems with Telegram. if e.message in ("Bad Gateway", "Timed out"): sleep(1) + elif e.message == "Unauthorized": + # The user has removed or blocked the bot. + update_id += 1 else: raise e except URLError as e: