fix timeouts?

This commit is contained in:
Tomáš Mládek 2018-04-26 18:03:28 +02:00 committed by Tomáš Mládek
parent cb25c2baf3
commit 77f3c2fc10

View file

@ -118,39 +118,31 @@ def handle_hashtag(bot, update):
# noinspection PyBroadException # noinspection PyBroadException
def handle(urls, message, download, filename=None): def handle(urls, message, download, filename=None):
tries = 0 try:
while tries < 3: logger.info("Downloading %s" % urls)
try: hashtag = get_first_hashtag(message)
logger.info("Downloading %s" % urls)
hashtag = get_first_hashtag(message)
if hashtag == 'IGNORE': if hashtag == 'IGNORE':
message.reply_text('Ignoring...') message.reply_text('Ignoring...')
return return
reply = 'Downloading' reply = 'Downloading'
if hashtag: if hashtag:
mkdir_p(f'{OUT_DIR}/{hashtag}') mkdir_p(f'{OUT_DIR}/{hashtag}')
reply += f' to "{hashtag}"' reply += f' to "{hashtag}"'
reply += '...' reply += '...'
if hashtag == 'AUDIO' and download != download_raw: if hashtag == 'AUDIO' and download != download_raw:
reply += ' (And also guessing you want to extract the audio)' reply += ' (And also guessing you want to extract the audio)'
message.reply_text(reply) message.reply_text(reply)
download(urls, download(urls,
hashtag or '.', message.date, hashtag or '.', message.date,
extract=(hashtag == 'AUDIO'), extract=(hashtag == 'AUDIO'),
filename=filename) filename=filename)
break except:
except: _, exc_value, __ = sys.exc_info()
_, exc_value, __ = sys.exc_info() if "Timed out" not in str(exc_value):
if "Timed out" not in str(exc_value): message.reply_text("Something is FUCKED: %s" % 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")
def handle_url(bot, update): def handle_url(bot, update):
@ -189,8 +181,13 @@ def start(bot, update):
def error(bot, update, error): def error(bot, update, error):
logger.error(error) logger.error(error)
if update is not None: if "Timed out" in error:
update.message.reply_text("Something is fucked: %s" % 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(): def main():