cquest / tootbot

python bot to clone tweets to a mastodon account
GNU Affero General Public License v3.0
101 stars 35 forks source link

Nested exception when a tweet contains photos and videos #26

Open javerous opened 1 year ago

javerous commented 1 year ago

Apparently, it's not possible to mix photos and videos in a toot, contrary to a tweet. Mastodon API raises an exception in this case when the script try to post such toot.

There is a catch, then a 10s wait, but the script re-do the same, and the same exception is raised again.

I did a temporary "fix" by changing

        try:
            if len(toot_media)>0:
                time.sleep(5)
            toot = mastodon_api.status_post(c,
                                        in_reply_to_id=None,
                                        media_ids=toot_media,
                                        sensitive=False,
                                        visibility='unlisted',
                                        spoiler_text=None)
        except:
            print("10s delay")
            time.sleep(10)
            toot = mastodon_api.status_post(c,
                                            in_reply_to_id=None,
                                            media_ids=toot_media,
                                            sensitive=False,
                                            visibility='unlisted',
                                            spoiler_text=None)
            pass

to

        try:
            if len(toot_media)>0:
                time.sleep(5)
            toot = mastodon_api.status_post(c,
                                        in_reply_to_id=None,
                                        media_ids=toot_media,
                                        sensitive=False,
                                        visibility='unlisted',
                                        spoiler_text=None)
        except:
            print("10s delay")
            time.sleep(10)
            toot = mastodon_api.status_post(c,
                                            in_reply_to_id=None,
                                            media_ids=[],
                                            sensitive=False,
                                            visibility='unlisted',
                                            spoiler_text=None)
            pass

But I guess there is a better way to fix that (I'm very far from being a Python expert…)