From 43d39200230ab439dddac4e6536d95183d98eed2 Mon Sep 17 00:00:00 2001 From: blank X Date: Thu, 12 Nov 2020 19:45:46 +0700 Subject: [PATCH] Not fail on non-valid gallery images --- redditbot.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/redditbot.py b/redditbot.py index b3484df..64d7adc 100644 --- a/redditbot.py +++ b/redditbot.py @@ -298,11 +298,12 @@ async def main(): files = [] captions = [] for a, i in enumerate(random_post.media_metadata): - captions.append(f'{text}\n#{a + 1}') - filename = os.path.join(tempdir, str(time.time())) i = random_post.media_metadata[i] - await _download_file(filename, i['s']['u']) - files.append(filename) + if i['status'] == 'valid': + filename = os.path.join(tempdir, str(time.time())) + await _download_file(filename, i['s']['u']) + captions.append(f'{text}\n#{a + 1}') + files.append(filename) url = None if url: parsed = list(urlparse(url))