From 5de192097a2bfc1a7ba13445839cbd85d3afa865 Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Sat, 21 Mar 2020 11:01:10 +0100 Subject: [PATCH 1/3] add more debugging output to apod module uploading a file --- modules/apod.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/apod.py b/modules/apod.py index d7a5541..211e26d 100644 --- a/modules/apod.py +++ b/modules/apod.py @@ -113,14 +113,19 @@ class MatrixModule(BotModule): async def upload_image(self, bot, url): self.client: AsyncClient response: UploadResponse + + self.logger.debug(f"start downloading image from url {url}") url_response = requests.get(url) + self.logger.debug(f"response [status_code={url_response.status_code}, headers={url_response.headers}") if url_response.status_code == 200: content_type = url_response.headers.get("content-type") + self.logger.info(f"uploading content to matrix server [size={len(url_response.content)}, content-type: {content_type}]") (response, alist) = await bot.client.upload(lambda a, b: url_response.content, content_type) + self.logger.debug("response: %s", response) if isinstance(response, UploadResponse): - self.logger.debug("uploaded file to %s", response.content_uri) + self.logger.info("uploaded file to %s", response.content_uri) return response.content_uri else: response: UploadError From 70c1a0bd66236abd57735e7a9a5c41cb15bd769e Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Thu, 26 Mar 2020 19:35:17 +0100 Subject: [PATCH 2/3] 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 :(") From d6a37754cd421186cb3555fb6efb5f25691e7867 Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Thu, 26 Mar 2020 19:41:26 +0100 Subject: [PATCH 3/3] handle image upload failure --- modules/apod.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/apod.py b/modules/apod.py index 3ee760c..ba4833d 100644 --- a/modules/apod.py +++ b/modules/apod.py @@ -101,17 +101,17 @@ class MatrixModule(BotModule): self.logger.warning("unable to upload hdurl. try url next.") matrix_uri = await self.upload_image(bot, apod.url) + await bot.send_text(room, f"{apod.title} ({apod.date})") 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}") - 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 :(") + 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}") async def upload_image(self, bot, url): self.client: AsyncClient