Skip to content

Instantly share code, notes, and snippets.

@zero-mstd
Last active February 8, 2022 16:09
Show Gist options
  • Save zero-mstd/f2725ae29f8c21939e8d3a1f328934d9 to your computer and use it in GitHub Desktop.
Save zero-mstd/f2725ae29f8c21939e8d3a1f328934d9 to your computer and use it in GitHub Desktop.
###############################################################################
# A tool for exporting rebloggers of one toot in Mastodon
# Author: Zero
# Last update: 2022-02-09
###############################################################################
# Usage
#
# 1. Save this code as `export_rebloggers.py` in your computer;
#
# 2. Edit it, note that there are three places need to be changed:
#
# a. <your_access_token_here> (line 30)
# 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 31)
# Replace it with the domain address of the instance you are using.
#
# c. <:id> (line 32)
# The id of the toot whose rebloggers you want to collect.
#
# 3. Execute this python file, and deal with the output as you like. For example,
# in Linux, you can `export_rebloggers.py > rebloggers_list`.
###############################################################################
import requests
import re
headers = {'Authorization': 'Bearer <your_access_token_here>'}
domain = 'https://<mastodon.example>/'
toot_id = '<:id>'
url = domain + 'api/v1/statuses/' + toot_id + '/reblogged_by'
i = 1
while 1:
fl = requests.get(url, headers = headers)
fj = fl.json()
for e in fj:
acct = e["acct"]
print(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