From 70c1a0bd66236abd57735e7a9a5c41cb15bd769e Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Thu, 26 Mar 2020 19:35:17 +0100 Subject: [PATCH] retry upload url if hdurl fails --- modules/apod.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/apod.py b/modules/apod.py index 211e26d..3ee760c 100644 --- a/modules/apod.py +++ b/modules/apod.py @@ -92,20 +92,23 @@ class MatrixModule(BotModule): await bot.send_text(room, f"{apod.explanation} || date: {apod.date} || original-url: {apod.url}") async def upload_and_send_image(self, room, bot, apod): - url = apod.hdurl if apod.hdurl is not None else apod.url - if apod.date in self.matrix_uri_cache: matrix_uri = self.matrix_uri_cache.get(apod.date) self.logger.debug(f"already uploaded picture {matrix_uri} for date {apod.date}") else: - matrix_uri = await self.upload_image(bot, url) + matrix_uri = await self.upload_image(bot, apod.hdurl) + if matrix_uri is None: + self.logger.warning("unable to upload hdurl. try url next.") + matrix_uri = await self.upload_image(bot, apod.url) if matrix_uri is not None: self.matrix_uri_cache[apod.date] = matrix_uri bot.save_settings() await bot.send_text(room, f"{apod.title} ({apod.date})") await bot.send_image(room, matrix_uri, f"{apod.title}") - await bot.send_text(room, f"original-url: {url}") + if apod.hdurl is not None: + await bot.send_text(room, f"original-hdurl: {apod.hdurl}") + await bot.send_text(room, f"original-url: {apod.url}") await bot.send_text(room, f"{apod.explanation}") else: await bot.send_text(room, "sorry. something went wrong uploading the image to matrix server :(")