Skip to content

Instantly share code, notes, and snippets.

@bhattisatish
Created October 8, 2023 16:16
Show Gist options
  • Save bhattisatish/a14527dbd5e01ced179bd7d3cc567ff2 to your computer and use it in GitHub Desktop.
Save bhattisatish/a14527dbd5e01ced179bd7d3cc567ff2 to your computer and use it in GitHub Desktop.
How far did my post go on the Fediverse?
# Original Src: https://shkspr.mobi/blog/2023/09/how-far-did-my-post-go-on-the-fediverse/
import config
from mastodon import Mastodon
from rich.pretty import pprint
# Set up access
mastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token, ratelimit_method='pace' )
# Status to check for
status_id = 111040801202691232
print("Looking up status: " + str(status_id))
# Get my data
me = mastodon.me()
my_id = me["id"]
print("You have User ID: " + str(my_id))
# Empty sets
instances_all = set()
instances_followers = set()
instances_reposters = set()
instances_reposters_followers = set()
instances_favourites = set()
# My Followers
followers = mastodon.account_followers( my_id )
print( "Getting all followers" )
followers_all = mastodon.fetch_remaining( followers )
print("Total followers = " + str( len(followers_all) ) )
# Get the server names of all my followers
for follower in followers_all:
if ( "@" in follower["acct"]) :
f = follower["acct"].split("@")[1]
instances_all.add( f )
if ( f not in instances_followers):
print( "Follower: " + f )
instances_followers.add( f )
else :
instances_all.add( "mastodon.social" )
instances_followers.add( "mastodon.social" )
total_followers = len(instances_followers)
print( "Total Unique Followers Instances = " + str(total_followers) )
# Reposters
# Find the accounts which reposted my status
reposters = mastodon.status_reblogged_by( status_id )
reposters_all = mastodon.fetch_remaining(reposters)
# Get all the instance names of my reposters
for reposter in reposters_all:
if ( "@" in reposter["acct"]) :
r = reposter["acct"].split("@")[1]
instances_all.add( r )
if ( r not in instances_followers ) :
print( "Reposter: " + r )
instances_reposters.add( r )
total_reposters = len(instances_reposters)
print( "Total Unique Reposters Instances = " + str(total_reposters) )
# Followers of reposters
# This can take a *long* time!
for reposter in reposters_all:
if ( "@" not in reposter["acct"]) :
reposter_id = reposter["id"]
print( "Getting followers of reposter " + reposter["acct"] + " with ID " + str(reposter_id) )
reposter_followers = mastodon.account_followers( reposter_id )
reposter_followers_all = mastodon.fetch_remaining( reposter_followers )
for reposter_follower in reposter_followers_all:
if ( "@" in reposter_follower["acct"]) :
f = reposter_follower["acct"].split("@")[1]
instances_all.add( f )
if (f not in instances_reposters_followers) :
print( " Adding " + f + " from " + reposter["acct"] )
instances_reposters_followers.add( f )
total_instances_reposters_followers = len(instances_reposters_followers)
print( "Total Unique Reposters' Followers Instances = " + str(total_instances_reposters_followers) )
# Favourites
# Find the accounts which favourited my status
favourites = mastodon.status_favourited_by( status_id )
favourites_all = mastodon.fetch_remaining(favourites)
# Get all the instance names of my favourites
for favourite in favourites_all:
if ( "@" in favourite["acct"]) :
f = favourite["acct"].split("@")[1]
instances_all.add( f )
if ( f not in instances_favourites ) :
print( "Favourite: " + f )
instances_favourites.add( r )
total_favourites = len(instances_favourites)
print( "Total Unique Favourites Instances = " + str(total_favourites) )
print( "Total Unique Reposters Instances = " + str(total_reposters) )
print( "Total Unique Followers Instances = " + str(total_followers) )
print( "Total Unique Reposters' Followers Instances = " + str( len(instances_reposters_followers) ) )
print( "Total Unique Instances = " + str( len(instances_all) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment