Skip to content

Instantly share code, notes, and snippets.

@thexyno
Created April 27, 2022 00:13
Show Gist options
  • Save thexyno/675a875afbb43e52f4eab8ff612f2072 to your computer and use it in GitHub Desktop.
Save thexyno/675a875afbb43e52f4eab8ff612f2072 to your computer and use it in GitHub Desktop.
A script to follow all accounts given via stdin on mastodon
#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p python3Packages.mastodon-py
from mastodon import Mastodon
import argparse
import sys
import time
parser = argparse.ArgumentParser(description='follow a (newline terminated) list of mastodon accounts, given via stdin')
parser.add_argument('-t', '--token', help='oauth2 token')
parser.add_argument('--url', help='mastodon url (mastodon.social, chaos.social, ...)', default='chaos.social')
args = parser.parse_args()
mastodon = Mastodon(
access_token=args.token,
api_base_url = f'https://{args.url}',
)
for line in sys.stdin:
if 'Exit' == line.rstrip():
break
search = mastodon.search(line.rstrip())
mastodon.account_follow(search['accounts'][0]['id'])
print(f'[+] following {line.rstrip()}')
time.sleep(5) # bird does not like new users
print("[+] Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment