-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_missing_follows.rb
executable file
·67 lines (49 loc) · 1.85 KB
/
find_missing_follows.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
# Example: fetch the list of accounts followed by a given user and check which of them have been deleted / deactivated.
# load minisky from a local folder - you normally won't need this
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
require 'didkit'
require 'minisky'
handle = ARGV[0].to_s.gsub(/^@/, '')
if handle.empty?
puts "Usage: #{$PROGRAM_NAME} <handle>"
exit 1
end
pds_host = DID.resolve_handle(handle).get_document.pds_endpoint
pds = Minisky.new(pds_host, nil, progress: '.')
print "Fetching all follows of @#{handle} from #{pds_host}: "
follows = pds.fetch_all('com.atproto.repo.listRecords',
{ repo: handle, collection: 'app.bsky.graph.follow', limit: 100 }, field: 'records')
puts
puts "Found #{follows.length} follows"
appview = Minisky.new('api.bsky.app', nil)
profiles = []
i = 0
puts
print "Fetching profiles of all followed accounts: "
# getProfiles lets us load multiple profiles in one request, but only up to 25 in one batch
while i < follows.length
batch = follows[i...i+25]
dids = batch.map { |x| x['value']['subject'] }
print '.'
result = appview.get_request('app.bsky.actor.getProfiles', { actors: dids })
profiles += result['profiles']
i += 25
end
# these are DIDs that are on the follows list, but aren't being returned from getProfiles
missing = follows.map { |x| x['value']['subject'] } - profiles.map { |x| x['did'] }
puts
puts "#{missing.length} followed accounts are missing:"
puts
missing.each do |did|
begin
doc = DID.new(did).get_document
rescue OpenURI::HTTPError
puts "#{did} (?) => DID not found"
next
end
# check account status on their assigned PDS
pds = Minisky.new(doc.pds_endpoint, nil)
status = pds.get_request('com.atproto.sync.getRepoStatus', { did: did }).slice('status', 'active') rescue 'deleted'
puts "#{did} (@#{doc.handles.first}) => #{status}"
end