Skip to content

Instantly share code, notes, and snippets.

@superboum
Last active June 5, 2020 08:51
Show Gist options
  • Save superboum/ad0570587307b420688a9a2721712f9e to your computer and use it in GitHub Desktop.
Save superboum/ad0570587307b420688a9a2721712f9e to your computer and use it in GitHub Desktop.
while true; do
to_wait=$(( (`date -d "$(date "+%Y-%m-%d %H:%M:56")" +%s` - `date +%s` + 60) % 60 + 1)) ;
sleep $to_wait ;
ip1=$(curl -sSkv --header "Host: api.stopcovid.gouv.fr" https://148.253.97.12/api/v1/status 2>&1 | grep x-ratelimit-remaining-minute | grep -Po "[0-9]+");
ip2=$(curl -sSkv --header "Host: api.stopcovid.gouv.fr" https://148.253.97.16/api/v1/status 2>&1 | grep x-ratelimit-remaining-minute | grep -Po "[0-9]+");
ip3=$(curl -sSkv --header "Host: api.stopcovid.gouv.fr" https://148.253.97.86/api/v1/status 2>&1 | grep x-ratelimit-remaining-minute | grep -Po "[0-9]+");
ts=$(date +%s);
now=$(( $ip1 + $ip2 + $ip3 ));
extra=$(( (180000 - $now - 3) * 60/57 * 60 * 24 ));
if [ -z "$ip1" ] || [ -z "$ip2"] || [ -z "$ip3" ]; then now="" ; extra="" ; fi ;
echo "$ts,$now,$extra,$ip1,$ip2,$ip3" ;
curl -s -i -XPOST 'https://<redacted>/write?db=stopcovid&precision=s' -u stopcovid:<redacted> --data-binary "ratelimit_remaining_minute value=$now $ts" 2>/dev/null 1>/dev/null &
curl -s -i -XPOST 'https://<redacted>/write?db=stopcovid&precision=s' -u stopcovid:<redacted> --data-binary "user_extrapolation value=$extra $ts" 2>/dev/null 1>/dev/null &
curl -s -i -XPOST 'https://<redacted>/write?db=stopcovid&precision=s' -u stopcovid:<redacted> --data-binary "ratelimit_remaining_minute_per_kong,ip=148.253.97.12 value=$ip1 $ts" 2>/dev/null 1>/dev/null &
curl -s -i -XPOST 'https://<redacted>/write?db=stopcovid&precision=s' -u stopcovid:<redacted> --data-binary "ratelimit_remaining_minute_per_kong,ip=148.253.97.16 value=$ip2 $ts" 2>/dev/null 1>/dev/null &
curl -s -i -XPOST 'https://<redacted>/write?db=stopcovid&precision=s' -u stopcovid:<redacted> --data-binary "ratelimit_remaining_minute_per_kong,ip=148.253.97.86 value=$ip3 $ts" 2>/dev/null 1>/dev/null &
done >> stop.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment