From 77f3c2fc104ea99989929727d8667b9f5ad53574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 26 Apr 2018 18:03:28 +0200 Subject: [PATCH] fix timeouts? --- delojza.py | 61 ++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/delojza.py b/delojza.py index d27872f..31faf8b 100755 --- a/delojza.py +++ b/delojza.py @@ -118,39 +118,31 @@ def handle_hashtag(bot, update): # noinspection PyBroadException def handle(urls, message, download, filename=None): - tries = 0 - while tries < 3: - try: - logger.info("Downloading %s" % urls) - hashtag = get_first_hashtag(message) + try: + logger.info("Downloading %s" % urls) + hashtag = get_first_hashtag(message) - if hashtag == 'IGNORE': - message.reply_text('Ignoring...') - return + if hashtag == 'IGNORE': + message.reply_text('Ignoring...') + return - reply = 'Downloading' - if hashtag: - mkdir_p(f'{OUT_DIR}/{hashtag}') - reply += f' to "{hashtag}"' - reply += '...' + reply = 'Downloading' + if hashtag: + mkdir_p(f'{OUT_DIR}/{hashtag}') + reply += f' to "{hashtag}"' + reply += '...' - if hashtag == 'AUDIO' and download != download_raw: - reply += ' (And also guessing you want to extract the audio)' - message.reply_text(reply) - download(urls, - hashtag or '.', message.date, - extract=(hashtag == 'AUDIO'), - filename=filename) - break - except: - _, exc_value, __ = sys.exc_info() - if "Timed out" not in str(exc_value): - message.reply_text("Something is FUCKED: %s" % exc_value) - break - else: - tries += 1 - if tries == 3: - message.reply_text("Something is FUCKED, tried thrice and it's all wrong") + if hashtag == 'AUDIO' and download != download_raw: + reply += ' (And also guessing you want to extract the audio)' + message.reply_text(reply) + download(urls, + hashtag or '.', message.date, + extract=(hashtag == 'AUDIO'), + filename=filename) + except: + _, exc_value, __ = sys.exc_info() + if "Timed out" not in str(exc_value): + message.reply_text("Something is FUCKED: %s" % exc_value) def handle_url(bot, update): @@ -189,8 +181,13 @@ def start(bot, update): def error(bot, update, error): logger.error(error) - if update is not None: - update.message.reply_text("Something is fucked: %s" % error) + if "Timed out" in error: + if update is not None: + update.message.reply_text("Now for realz tho") + handle_rest(bot, update) + else: + if update is not None: + update.message.reply_text("Something is fucked: %s" % error) def main():