diff --git a/libforget/mastodon.py b/libforget/mastodon.py index 5de06fe..b2b5a6e 100644 --- a/libforget/mastodon.py +++ b/libforget/mastodon.py @@ -1,6 +1,7 @@ from mastodon import Mastodon from mastodon.Mastodon import MastodonAPIError,\ MastodonNetworkError,\ + MastodonNotFoundError,\ MastodonRatelimitError,\ MastodonUnauthorizedError from model import MastodonApp, Account, OAuthToken, Post, MastodonInstance @@ -185,16 +186,14 @@ def refresh_posts(posts): status = api.status(post.mastodon_id) new_post = db.session.merge( post_from_api_object(status, post.mastodon_instance)) + new_post.touch() new_posts.append(new_post) + except MastodonNotFoundError: + db.session.delete(post) except (MastodonAPIError, MastodonNetworkError, MastodonRatelimitError) as e: - if any([ - err in str(e) - for err in ('Endpoint not found', 'Record not found')]): - db.session.delete(post) - else: - raise TemporaryError(e) + raise TemporaryError(e) return new_posts diff --git a/libforget/twitter.py b/libforget/twitter.py index 9645632..67b1e6a 100644 --- a/libforget/twitter.py +++ b/libforget/twitter.py @@ -193,6 +193,7 @@ def refresh_posts(posts): db.session.delete(post) else: post = db.session.merge(post_from_api_tweet_object(tweet)) + post.touch() refreshed_posts.append(post) return refreshed_posts diff --git a/tasks.py b/tasks.py index f879035..e3a4994 100644 --- a/tasks.py +++ b/tasks.py @@ -231,6 +231,8 @@ def refresh_posts(posts): def refresh_account(account_id): account = Account.query.get(account_id) + print("Refreshing account {}".format(account)) + try: limit = 100 if account.service == 'mastodon':