Monorepo for @ducky.ws's experiments and scripts ducky.ws

didweb-leaderboard: add bash script

+75
+75
code/bash/didweb-leaderboard.sh
··· 1 + #!/bin/bash 2 + 3 + data=$(curl -s https://raw.githubusercontent.com/mary-ext/atproto-scraping/refs/heads/trunk/state.json) 4 + did_webs=$(echo "$data" | jq -r '.firehose.didWebs | to_entries[] | select(.key | startswith("did:web")) | .key') 5 + 6 + if [[ -n "$EXTRA_DIDS" ]]; then 7 + IFS=',' read -ra extra_dids <<< "$EXTRA_DIDS" 8 + for did in "${extra_dids[@]}"; do 9 + if [[ -n "$did" ]]; then 10 + did_webs+=$'\n'"$did" 11 + fi 12 + done 13 + fi 14 + 15 + echo "DID,Handle,Followers,Following,Posts,Last Post,Created,Status" > output.csv 16 + 17 + while IFS= read -r did; do 18 + profile="" 19 + status="" 20 + 21 + if [[ -n "$did" ]]; then 22 + #if [[ "$(curl -s -L -w "%{http_code}" -o /dev/null "https://$(echo "$did" | sed 's/did:web://' | sed 's/:/\//g')/.well-known/did.json")" =~ ^2[0-9][0-9]$ ]]; then 23 + profile=$(curl -s "https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=$did" 2>/dev/null) 24 + #else 25 + # status="💥 Broken" 26 + #fi 27 + 28 + created_at="" 29 + followers=0 30 + following=0 31 + last_post_at="" 32 + handle="" 33 + posts=0 34 + 35 + if echo "$profile" | jq -e '.error' > /dev/null 2>&1; then 36 + [[ -z $status ]] && status="🗑️ Deactivated" 37 + else 38 + created_at=$(echo "$profile" | jq -r '.createdAt // ""') 39 + handle=$(echo "$profile" | jq -r '.handle // ""') 40 + followers=$(echo "$profile" | jq -r '.followersCount // 0') 41 + following=$(echo "$profile" | jq -r '.followsCount // 0') 42 + posts=$(echo "$profile" | jq -r '.postsCount // 0') 43 + 44 + if [[ "$handle" == "handle.invalid" ]]; then 45 + handle="" 46 + status="💥 Broken" 47 + fi 48 + 49 + if [[ -n "$posts" ]] && [ "$posts" -gt 0 ]; then 50 + feed=$(curl -s "https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=$did&limit=1" 2>/dev/null) 51 + last_post_at=$(echo "$feed" | jq -r '.feed[0].post.record.createdAt // ""') 52 + 53 + if [ -n "$last_post_at" ]; then 54 + last_post_at_sec=$(date -u -d "$last_post_at" +%s 2>/dev/null || echo 0) 55 + thirty_days_ago_sec=$(date -u -d "30 days ago" +%s) 56 + 57 + if [ "$last_post_at_sec" -ge "$thirty_days_ago_sec" ] && [ "$followers" -gt 0 ] && [ "$posts" -gt 0 ]; then 58 + [[ -z $status ]] && status="✅ Active" 59 + else 60 + [[ -z $status ]] && status="❌ Inactive" 61 + fi 62 + fi 63 + else 64 + status="🤔 Dormant" 65 + fi 66 + 67 + [[ "$created_at" == "0001-01-01T00:00:00.000Z" ]] && created_at="" 68 + fi 69 + 70 + echo "$did | $handle | $followers / $following / $posts | $last_post_at | $created_at | $status" 71 + echo "$did,$handle,$followers,$following,$posts,$last_post_at,$created_at,$status" >> output.csv 72 + 73 + sleep 0.5 74 + fi 75 + done <<< "$did_webs"