Created
December 21, 2022 21:45
-
-
Save benwbrum/aeeb5bca22fef1f944583727ee965fc3 to your computer and use it in GitHub Desktop.
Script to read the public profile directory from one or more mastodon servers and produce a spreadsheet with account descriptions and names
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
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'pry' | |
require 'json' | |
f = File.open("accounts.csv", "w+") | |
f.print ['username','display name', 'account', 'created', 'posts', 'followers', 'following', 'note'].join("\t") | |
f.print "\n" | |
while server = ARGV.shift do | |
offset = 0 | |
records = [] | |
while records.size > 0 || offset==0 | |
api_endpoint = "https://#{server}/api/v1/directory?order=new&local=true&limit=20&offset=#{offset}" | |
handle = URI.open(api_endpoint) | |
response = handle.read | |
records = JSON.parse(response) | |
records.each do |profile| | |
f.print [ | |
profile['username'], | |
profile['display_name'], | |
"@" + profile['username'] + '@' + server, | |
profile['created_at'], | |
profile['statuses_count'], | |
profile['followers_count'], | |
profile['following_count'], | |
profile['note'] | |
].join("\t") | |
f.print "\n" | |
end | |
offset += 20 | |
sleep 3 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment