Created
September 6, 2024 22:40
-
-
Save mackuba/99110c07736570c02220038c1b716817 to your computer and use it in GitHub Desktop.
Script to check how much given Bluesky users post daily on average
This file contains 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 | |
begin | |
require 'minisky' | |
rescue LoadError | |
puts "Install minisky: '[sudo] gem install minisky'" | |
exit 1 | |
end | |
require 'time' | |
if ARGV.empty? | |
puts "Usage: [DAYS=14] #{$PROGRAM_NAME} @handle @other.handle ..." | |
exit 1 | |
end | |
bsky = Minisky.new('public.api.bsky.app', nil) | |
post_map = {} | |
days = ENV['DAYS']&.to_f || 7.0 | |
start_time = Time.now - 86400 * days | |
ARGV.each do |arg| | |
handle = arg.gsub(/^@/, '') | |
print "@#{handle} " | |
post_map[handle] = bsky.fetch_all( | |
'app.bsky.feed.getAuthorFeed', | |
{ actor: handle, limit: 100 }, | |
field: 'feed', | |
progress: '.', | |
break_when: ->(x) { | |
post_time = x['reason'] ? x['reason']['indexedAt'] : x['post']['indexedAt'] | |
Time.parse(post_time) < start_time | |
} | |
) | |
puts | |
end | |
max_length = post_map.keys.map(&:length).max || 0 | |
fields = [ | |
"handle".ljust(max_length + 3), | |
'feed/d'.rjust(7), | |
'own/d'.rjust(7), | |
'RTs/d'.rjust(7), | |
'rpls/d'.rjust(7) | |
] | |
puts | |
puts fields.join(' ') | |
puts '-' * fields.join(' ').length | |
table = [] | |
post_map.each do |handle, all_posts| | |
posts = all_posts.select { |t| t['reason'].nil? } | |
reposts = all_posts.select { |t| t['reason'] } | |
replies = posts.select { |t| t['reply'] } | |
own_posts = posts - replies | |
feed_posts = reposts + own_posts | |
table << [ | |
('@' + handle).ljust(max_length + 3), | |
sprintf('%.1f', feed_posts.length / days).rjust(7), | |
sprintf('%.1f', own_posts.length / days).rjust(7), | |
sprintf('%.1f', reposts.length / days).rjust(7), | |
sprintf('%.1f', replies.length / days).rjust(7) | |
] | |
end | |
table.sort_by { |r| -r[1].to_f }.each do |fields| | |
puts fields.join(' ') | |
end | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment