Skip to content

Instantly share code, notes, and snippets.

@promovicz
Last active November 16, 2022 14:07
Show Gist options
  • Select an option

  • Save promovicz/d7759720be0c582ad6539c28f59115ad to your computer and use it in GitHub Desktop.

Select an option

Save promovicz/d7759720be0c582ad6539c28f59115ad to your computer and use it in GitHub Desktop.
Mastodon: script that unsuspends all users given on the command line
#!/usr/bin/python3
# spontaneously smashed together by @promovicz@chaos.social
# in response to a question by @TheGibson@hackers.town
from argparse import ArgumentParser
from mastodon import Mastodon
ap = ArgumentParser('unsuspend')
ap.add_argument('-i',type=str,help='instance',default='chaos.social')
ap.add_argument('-t',type=str,help='token (string or file)',default='secret.key')
ap.add_argument('u',type=str,nargs='*',help='users')
a = ap.parse_args()
m = Mastodon(api_base_url=a.i,access_token=a.t)
users = []
for uid in a.u:
results = m.account_search(uid)
if len(results) == 0:
raise Exception('User %s not found' % uid)
elif len(results) > 1:
raise Exception('User %s is ambiguous' % uid)
users += results
for user in users:
print("unsuspending %d" % user.id)
m.admin_account_unsuspend(user)
@promovicz
Copy link
Author

This script allows unsuspending users in batch on the command-line.

It will only accept locally unambiguous user names, so be sure to provide the whole identifier.

Admin privileges are obviously required.

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