Last active
March 4, 2021 08:45
-
-
Save oskar456/8fd120079888827c9288b6fb7910cd5b to your computer and use it in GitHub Desktop.
Claim 1,000,000 RIPE Atlas credits every time you can
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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