From 173060d2d3bfe56d3fc7df7d59bdf14bc7c0ed83 Mon Sep 17 00:00:00 2001 From: Holly Date: Wed, 17 Mar 2021 19:42:23 +0000 Subject: [PATCH] Revert "upload attachments asynchronously" This reverts commit ec7d7176b05e9e6174ae3bd8a7edb1bd237de6fe. It turns out that Mastodon decides what order to show attachments using the order that they were uploaded, not the order of the media_ids parameter or anything. --- mtgcardlookup.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mtgcardlookup.py b/mtgcardlookup.py index 6d8e15e..3d5f0b1 100755 --- a/mtgcardlookup.py +++ b/mtgcardlookup.py @@ -169,14 +169,6 @@ async def update_followers(c, me): else: log('No accounts to unfollow.') -async def upload_image(c, image, desc): - card_name = desc.split('\n')[0].split(' - ')[0] - log(f'Uploading {card_name}...') - id = (await c.upload_attachment(fileobj=image, description=desc))['id'] - log(f'Done uploading {card_name}!') - return id - - async def listen(c, me): log('Listening...') async with c.streaming('user') as stream: @@ -235,9 +227,9 @@ async def listen(c, me): if media: try: - media_ids = await asyncio.gather( - *(upload_image(c, image, desc) for image, desc in media) - ) + media_ids = [] + for image, desc in media: + media_ids.append((await c.upload_attachment(fileobj=image, params={}, description=desc))['id']) except atoot.api.RatelimitError: media_ids = None reply_text += '\n\nMedia attachments are temporarily disabled due to API restrictions, they will return shortly.'