Skip to content

Instantly share code, notes, and snippets.

@oskar456
Last active March 4, 2021 08:45
Show Gist options
  • Save oskar456/8fd120079888827c9288b6fb7910cd5b to your computer and use it in GitHub Desktop.
Save oskar456/8fd120079888827c9288b6fb7910cd5b to your computer and use it in GitHub Desktop.
Claim 1,000,000 RIPE Atlas credits every time you can
#!/bin/bash
# Dependencies: curl, jq, realpath, date (GNU), at
API_KEY="FIXME"
claim_endpoint() {
local regid=$1
curl -s -H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"members": ["'$regid'"]}' \
"https://atlas.ripe.net:443/api/v2/credits/members/claim/?key=$API_KEY" | jq .
}
members_endpoint() {
curl -s -H "Content-Type: application/json" \
-H "Accept: application/json" \
"https://atlas.ripe.net:443/api/v2/credits/members/?key=$API_KEY" \
| jq -r '.members[]|(.reg_id+" "+(.can_claim|tostring)+" "+.next_claim)'
}
main() {
while read regid canclaim nextclaim
do
if [[ "$canclaim" = "true" ]]
then
claim_endpoint "$regid"
fi
done <<-EOF
$(members_endpoint)
EOF
local unextmin=$(date +%s -d "+ 40 days")
local unextclaim
local unow
while read regid canclaim nextclaim
do
unextclaim="$(date -d "${nextclaim}Z" +%s)"
unow="$(date +%s)"
if [[ "$unextclaim" -gt "$unow" && "$unextclaim" -lt "$unextmin" ]]
then
unextmin=$unextclaim
fi
done <<-EOF
$(members_endpoint)
EOF
at "$(date -d "@${unextmin}" +%H:%M\ %Y-%m-%d) + 1 minute" <<-EOF 2>/dev/null
bash "$(realpath "$0")"
EOF
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment