-
-
Save a-e-m/dfe0a1e3db0f79d54402572585016c54 to your computer and use it in GitHub Desktop.
Bluesky probable bot finding script
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
| import datetime | |
| import sys | |
| import time | |
| from atproto import Client | |
| def retry(func, attempts=3): | |
| for attempt in range(attempts): | |
| try: | |
| return func() | |
| except Exception as e: | |
| print(e) | |
| time.sleep(2 ** attempts) | |
| if attempt == (attempts - 1): | |
| raise e | |
| def get_all_followers(client, actor): | |
| cursor = None | |
| while True: | |
| response = retry(lambda: client.get_followers(actor=actor, cursor=cursor)) | |
| yield from response['followers'] | |
| cursor = response['cursor'] | |
| if not cursor: | |
| break | |
| if __name__ == "__main__": | |
| client = Client() | |
| try: | |
| client.login('USERNAME HERE', 'PASSWORD HERE') | |
| except Exception as e: | |
| print(e) | |
| sys.exit(1) | |
| me = client.me.did | |
| for follower in get_all_followers(client, me): | |
| handle = follower.handle.lower() | |
| description = (follower.description or '').lower() | |
| if not 'http' in description: | |
| # ignore accounts without links | |
| continue | |
| viewer_state = follower.viewer | |
| if viewer_state.blocking or viewer_state.blocked_by: | |
| # already blocked accounts | |
| continue | |
| profile = client.get_profile(handle) | |
| followers = profile.followers_count | |
| following = profile.follows_count | |
| if following > 10000 and (following / followers) > 5: | |
| print(handle, followers, following) | |
| client.com.atproto.repo.create_record({ | |
| "collection": "app.bsky.graph.listitem", | |
| # you should replace the next line with the info for your own moderation list | |
| "repo": "did:plc:lcnrh2plboj2yhzk6ndxc6dc", | |
| "record": { | |
| "subject":follower.did, | |
| # you should replace the next line with the info for your own moderation list | |
| "list":"at://did:plc:lcnrh2plboj2yhzk6ndxc6dc/app.bsky.graph.list/3luw5ry3wpo27", | |
| "createdAt": datetime.datetime.now(datetime.timezone.utc).isoformat(), | |
| "$type":"app.bsky.graph.listitem" | |
| }, | |
| }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment