Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip fetching context of private posts #139

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion find_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ def get_reply_toots(user_id, server, access_token, seen_urls, reply_since):
f"Error getting replies for user {user_id} on server {server}. Status code: {resp.status_code}"
)


def toot_context_can_be_fetched(toot):
fetchable = toot["visibility"] in ["public", "unlisted"]
if not fetchable:
logger.debug(f"Cannot fetch context of private toot {toot['uri']}")
return fetchable


def toot_context_should_be_fetched(toot):
if toot['uri'] not in recently_checked_context:
recently_checked_context[toot['uri']] = toot
Expand Down Expand Up @@ -512,7 +520,7 @@ def get_all_known_context_urls(server, reply_toots, parsed_urls, seen_hosts):
if toot_has_parseable_url(toot, parsed_urls):
url = toot["url"] if toot["reblog"] is None else toot["reblog"]["url"]
parsed_url = parse_url(url, parsed_urls)
if(toot_context_should_be_fetched(toot)):
if toot_context_can_be_fetched(toot) and toot_context_should_be_fetched(toot):
recently_checked_context[toot['uri']]['lastSeen'] = datetime.now(datetime.now().astimezone().tzinfo)
context = get_toot_context(parsed_url[0], parsed_url[1], url, seen_hosts)
if context is not None:
Expand Down