Skip to content

Instantly share code, notes, and snippets.

@svyatogor
Created March 30, 2020 09:50
Show Gist options
  • Save svyatogor/17e152f1fd19c40d014bc1702a37ec29 to your computer and use it in GitHub Desktop.
Save svyatogor/17e152f1fd19c40d014bc1702a37ec29 to your computer and use it in GitHub Desktop.
#!/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