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