Skip to content

Instantly share code, notes, and snippets.

@joshuap
Last active November 23, 2024 20:09
Show Gist options
  • Save joshuap/3950e8f809e5ac52550f4b0194f275cc to your computer and use it in GitHub Desktop.
Save joshuap/3950e8f809e5ac52550f4b0194f275cc to your computer and use it in GitHub Desktop.
Get the Bluesky DIDs for all members of a list.
#!/usr/bin/env bash
# Dependencies:
# https://github.com/myConsciousness/atproto.dart/tree/main/packages/bluesky_cli
# https://github.com/jqlang/jq
# Check if URI argument is provided
if [ $# -lt 1 ]; then
echo "Usage: $0 <list-uri> [output-file]"
exit 1
fi
LIST_URI="$1"
OUTPUT_FILE="${2:-bsky_list_output.txt}"
LIMIT=100 # Maximum allowed limit
TEMP_FILE=$(mktemp)
CURSOR=""
# Function to process the JSON response and extract DIDs
process_response() {
local response="$1"
echo "$response" | jq -r '.items[].subject.did' >> "$TEMP_FILE"
CURSOR=$(echo "$response" | jq -r '.cursor // empty')
}
# Clear output file if it exists
> "$OUTPUT_FILE"
echo "Fetching list members..."
# Initial request
RESPONSE=$(bsky list --uri "$LIST_URI" --limit $LIMIT)
process_response "$RESPONSE"
# Continue fetching while there's a cursor
while [ ! -z "$CURSOR" ]; do
echo "Fetching next page..."
RESPONSE=$(bsky list --uri "$LIST_URI" --limit $LIMIT --cursor "$CURSOR")
process_response "$RESPONSE"
done
# Sort and deduplicate results
sort -u "$TEMP_FILE" > "$OUTPUT_FILE"
# Cleanup and display results
rm "$TEMP_FILE"
TOTAL_COUNT=$(wc -l < "$OUTPUT_FILE")
echo "Done! Found $TOTAL_COUNT unique DIDs saved to $OUTPUT_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment