Forked from zero-mstd/export_mastodon_followers.py
Created
November 23, 2022 12:21
-
-
Save jdaviescoates/f48effbf973e8ab2092ff704647e5d2c to your computer and use it in GitHub Desktop.
A tool for exporting Mastodon followers
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
############################################################################### | |
# 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