Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdaviescoates/f48effbf973e8ab2092ff704647e5d2c to your computer and use it in GitHub Desktop.
Save jdaviescoates/f48effbf973e8ab2092ff704647e5d2c to your computer and use it in GitHub Desktop.
A tool for exporting Mastodon followers
###############################################################################
# A tool for exporting Mastodon followers
# Author: Zero
# Last update: 2022-02-09
###############################################################################
# Usage
#
# 1. Save this code as `export_mastodon_followers.py` in your computer.
#
# 2. Edit it, note that there are three places need to be changed:
#
# a. <your_access_token_here> (line 32)
# You can get your access token by: Settings -> Development ->
# NEW APPLICATION -> fill in an application name -> SUBMIT -> click your
# application name -> you will see your access token.
#
# b. <mastodon.example> (line 33)
# Replace it with the domain address of the instance you are using.
#
# c. <:id> (line 33)
# When you click one's avatar on Mastodon web UI, you can see the url
# is in this format: `https://<mastodon.example>/web/accounts/<:id>`, the
# last string of numbers is <:id>.
#
# 3. Execute this python file, and deal with the output as you like. For example,
# in Linux, you can `python export_mastodon_followers.py > followers_list`.
###############################################################################
import requests
import re
headers = {'Authorization': 'Bearer <your_access_token_here>'}
url = 'https://<mastodon.example>/api/v1/accounts/<:id>/followers'
i = 1
while 1:
fl = requests.get(url, headers = headers)
fj = fl.json()
for e in fj:
acct = e["acct"]
print(str(i) + ' ' + acct)
i = i + 1
if (not 'Link' in fl.headers) or (not 'rel="next"' in fl.headers['Link']):
break
else:
next_url = re.match(r"\<(.*?)\>", fl.headers['Link']).groups()[0]
url = next_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment