Last active
August 6, 2023 13:34
-
-
Save linusg/92405cf390e31f2bd1903e81fb4f7084 to your computer and use it in GitHub Desktop.
Prune blank profile followers from a Mastodon account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mastodon import Mastodon | |
CLIENT_SECRET = "..." | |
ACCESS_TOKEN = "..." | |
API_BASE_URL = "https://chaos.social" | |
mastodon = Mastodon( | |
client_secret=CLIENT_SECRET, | |
access_token=ACCESS_TOKEN, | |
api_base_url=API_BASE_URL, | |
) | |
print("Fetching own user profile...") | |
me = mastodon.me() | |
print("Fetching all followers...") | |
followers = mastodon.fetch_remaining(mastodon.account_followers(me["id"])) | |
print("Fetching all following...") | |
following = mastodon.fetch_remaining(mastodon.account_following(me["id"])) | |
following_ids = set(profile["id"] for profile in following) | |
print("Finding non-mutual followers with no avatar and note...") | |
prune = [ | |
profile | |
for profile in followers | |
if profile["id"] not in following_ids | |
and profile["avatar"].endswith("/avatars/original/missing.png") | |
and profile["note"] in ("", "<p></p>") | |
] | |
prune.sort(key=lambda profile: profile["url"]) | |
print(f"Found {len(prune)} profiles to prune:") | |
for profile in prune: | |
print(f"- {profile['url']}") | |
print("Removing followers...") | |
for profile in prune: | |
mastodon.account_remove_from_followers(profile["id"]) | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment