retry upload url if hdurl fails
This commit is contained in:
parent
5de192097a
commit
70c1a0bd66
|
@ -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 :(")
|
||||
|
|
Loading…
Reference in New Issue