Skip to content

Instantly share code, notes, and snippets.

@hamelsmu
Last active November 26, 2024 14:27
Show Gist options
  • Save hamelsmu/fb9ed633de7d784619e4b6da5039e6ae to your computer and use it in GitHub Desktop.
Save hamelsmu/fb9ed633de7d784619e4b6da5039e6ae to your computer and use it in GitHub Desktop.
"I'll have what they are having" for bluesky. The motiviation is to mimic who someone else is following who reports they are having a good experience on bluesky!
def follow_user_follows(client, target_user):
"Follow everyone the target_user is following."
cursor = None
total_followed = 0
while True:
# Step 1: Fetch a batch of accounts the target user is following
# https://docs.bsky.app/docs/api/app-bsky-graph-get-follows
response = client.app.bsky.graph.get_follows({
'actor': target_user,
'limit': 100,
'cursor': cursor
})
# Step 2: Iterate through the accounts
for follow in response.follows:
try:
# Step 3: Follow each account
client.follow(follow.did)
print(f'Following {follow.handle}')
total_followed += 1
# Step 4: Add a delay to respect rate limits
time.sleep(2)
except Exception as e:
print(f'Error following {follow.handle}: {str(e)}')
# Step 5: Check for more accounts to follow
if not response.cursor:
break
cursor = response.cursor
# Step 6: Print progress
print(f'Followed {total_followed} users so far')
# Step 7: Print final result
print(f'Finished following {total_followed} users')
# Step 8: Set up credentials
USERNAME = 'your_username.bsky.social'
APP_PASSWORD = 'your_app_password'
TARGET_USER = 'target_user.bsky.social'
# Step 9: Initialize and authenticate client
client = Client()
client.login(USERNAME, APP_PASSWORD)
# Step 10: Execute the follow process
follow_user_follows(client, TARGET_USER)
@simonw
Copy link

simonw commented Nov 24, 2024

I forked this to add script inline metadata for the dependency and use input() and getpass() to accept the credentials - now you can run it without having to install it first using uv like this:

uv run https://gist.githubusercontent.com/simonw/848a3b91169a789bc084a459aa7ecf83/raw/3480742855f20056324f276bf19e3e77ef52ef6e/follow_theirs.py

Code here: https://gist.github.com/simonw/848a3b91169a789bc084a459aa7ecf83

Diff here: https://gist.github.com/simonw/848a3b91169a789bc084a459aa7ecf83/revisions

@ricklamers
Copy link

# /// script
# dependencies = [
#   "atproto"
# ]
# ///
uv run https://

woah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment