Created
March 30, 2020 09:50
-
-
Save svyatogor/17e152f1fd19c40d014bc1702a37ec29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
yaml2json() { | |
ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' $* | |
} | |
PAPERTRAIL_TOKEN=$(cat ~/.papertrail.yml | yaml2json | jq -r .token) | |
FROM=$(date -j -u -f "%Y-%m-%d" "$1" +%s) | |
TO=$(date -j -u -f "%Y-%m-%d" $2 +%s) | |
curl -sH "X-Papertrail-Token: $PAPERTRAIL_TOKEN" https://papertrailapp.com/api/v1/archives.json | | |
jq -r "map(select((.start | fromdateiso8601) as \$t | (\$t >= $FROM and \$t <= $TO))) | .[]._links.download.href" | | |
awk '{ | |
url = $1 | |
gsub(/\/download/, ".tsv.gz", $1) | |
gsub(/.*archives\//, "", $1) | |
print "output " $1 | |
print "url " url | |
}' | curl --progress-bar -fLH "X-Papertrail-Token: $PAPERTRAIL_TOKEN" -K- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment