Skip to content

Commit ae78954

Browse files
authored
Merge pull request #41 from IntersectMBO/add-script-to-query-actions
add script to query live actions
2 parents 2706399 + 1750b16 commit ae78954

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

scripts/query-live-actions.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Dependencies: curl, jq
4+
API_BASE="https://api.koios.rest/api/v1"
5+
6+
# Get all proposals from Koios
7+
echo "Fetching proposal list from Koios..."
8+
proposals=$(curl -s -X GET "$API_BASE/proposal_list" -H "accept: application/json")
9+
10+
# Filter for proposals that are still active (not ratified, enacted, dropped, expired)
11+
active_proposals=$(echo "$proposals" | jq -c '.[] | select(
12+
(.ratified_epoch == null) and
13+
(.enacted_epoch == null) and
14+
(.dropped_epoch == null) and
15+
(.expired_epoch == null)
16+
)')
17+
18+
echo "Fetching voting summaries and titles for active proposals..."
19+
20+
results=()
21+
22+
while IFS= read -r proposal; do
23+
pid=$(echo "$proposal" | jq -r .proposal_id)
24+
25+
# Extract the title from meta_json.body.title (fallback to "No Title" if missing)
26+
title=$(echo "$proposal" | jq -r '.meta_json.body.title // "No Title found"')
27+
28+
# Fetch the voting summary
29+
summary=$(curl -s -X GET "$API_BASE/proposal_voting_summary?_proposal_id=$pid" -H "accept: application/json")
30+
31+
if [[ $(echo "$summary" | jq 'length') -gt 0 ]]; then
32+
row=$(echo "$summary" | jq -r --arg id "$pid" --arg title "$title" '
33+
.[0] | {
34+
proposal_id: $id,
35+
title: $title,
36+
drep_yes_pct,
37+
drep_no_pct,
38+
drep_abstain_votes_cast,
39+
drep_yes_votes_cast,
40+
drep_no_votes_cast
41+
}'
42+
)
43+
results+=("$row")
44+
fi
45+
done <<< "$(echo "$active_proposals")"
46+
47+
# Sort and display the results by drep_yes_pct (descending)
48+
echo -e "\nSorted Active Proposals by drep_yes_pct:"
49+
printf '%s\n' "${results[@]}" | jq -s 'sort_by(.drep_yes_pct | tonumber) | reverse[]'

0 commit comments

Comments
 (0)