Created
July 4, 2024 14:14
-
-
Save mackuba/c86dfa8fc863cec243700c3e67c3978c to your computer and use it in GitHub Desktop.
Script for deleting all items from a list (even if the list itself was deleted)
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 | |
# to install minisky: `gem install minisky` | |
require 'minisky' | |
list_id = ARGV[0] | |
if list_id.nil? | |
puts "Usage: #{$PROGRAM_NAME} <list_rkey>" | |
puts "(rkey is the last part of the list URL after the last slash)" | |
exit 1 | |
end | |
if !File.exist?('config.yml') | |
puts "Missing config.yml file" | |
puts "Prepare a config.yml file with:" | |
puts | |
puts "id: my.handle.social" | |
puts "pass: app_password" | |
exit 1 | |
end | |
sky = Minisky.new('bsky.social', 'config.yml', progress: '.') | |
sky.check_access | |
puts "Loading list items:" | |
items = sky.fetch_all('com.atproto.repo.listRecords', | |
{ collection: 'app.bsky.graph.listitem', repo: sky.user.did, limit: 100 }, field: 'records') | |
matching_items = items.select { |x| x['value']['list'].split('/').last == list_id } | |
puts | |
puts "Found #{items.length} items, #{matching_items.length} from list #{list_id}" | |
puts | |
puts "Deleting matching items:" | |
matching_items.each do |x| | |
sky.post_request('com.atproto.repo.deleteRecord', { | |
collection: 'app.bsky.graph.listitem', repo: sky.user.did, rkey: x['uri'].split('/').last | |
}) | |
print '.' | |
end | |
puts | |
puts "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment