From f51d19730b490904f0cb8f10ee16953ae137a2f1 Mon Sep 17 00:00:00 2001 From: nanos Date: Fri, 31 Mar 2023 17:23:12 +0100 Subject: [PATCH] put a cap on mentions to backfill during any given executions --- find_posts.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/find_posts.py b/find_posts.py index 808741c..2ed7da2 100644 --- a/find_posts.py +++ b/find_posts.py @@ -78,13 +78,20 @@ def pull_context( # Backfill any post authors, and any mentioned users mentioned_users = [] for toot in timeline_toots: - mentioned_users = mentioned_users + [toot['account']] - if(len(toot['mentions'])): - mentioned_users = mentioned_users + toot['mentions'] - if(toot['reblog'] != None): - mentioned_users = mentioned_users + [toot['reblog']['account']] - if(len(toot['reblog']['mentions'])): - mentioned_users = mentioned_users + toot['reblog']['mentions'] + these_users = [] + toot_created_at = parser.parse(toot['created_at']) + cutoff = datetime.now(datetime.now().astimezone().tzinfo) - timedelta(minutes=60) + if(len(mentioned_users) < 10 or toot_created_at > cutoff): + these_users.append(toot['account']) + if(len(toot['mentions'])): + these_users += toot['mentions'] + if(toot['reblog'] != None): + these_users.append(toot['reblog']['account']) + if(len(toot['reblog']['mentions'])): + these_users += toot['reblog']['mentions'] + for user in these_users: + if user not in mentioned_users and user['acct'] not in all_known_users: + mentioned_users.append(user) add_user_posts(server, access_token, filter_known_users(mentioned_users, all_known_users), recently_checked_users, all_known_users, seen_urls)