fix timeouts?

feature-unify_handlers
Tomáš Mládek 2018-04-26 18:03:28 +02:00 committed by Tomáš Mládek
parent cb25c2baf3
commit 77f3c2fc10
1 changed files with 29 additions and 32 deletions

View File

@ -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():