Created
September 29, 2016 22:54
-
-
Save avioli/097b3e78b984d3f8fe99b8d335c6fa90 to your computer and use it in GitHub Desktop.
A basic fetcher for ANZ bank loan rates
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
#!/usr/bin/env bash | |
## NOTE(evo): `brew install jq` | |
if test -z "$JQ_BIN"; then | |
hash jq 2>/dev/null || { echo "jq is required: brew install jq"; exit 1; } | |
fi | |
test -z "$JQ_BIN" && JQ_BIN=jq | |
test -z "$TMPDIR" && TMPDIR=/tmp | |
test -z "$OUTFILE" && OUTFILE="$TMPDIR/anz.js" | |
test -z "$BAKFILE" && BAKFILE="$TMPDIR/anz.old.js" | |
find "$OUTFILE" -mmin +120 -exec mv "$OUTFILE" "$BAKFILE" \; 2>/dev/null | |
if test ! -e "$OUTFILE"; then | |
curl -Ls "https://www.anz.com/productdata/productdata.asp?output=json&callback=callbackFunction&country=AU§ion=&subsection=" | \ | |
tail -c +18 | \ # remove `callbackFunction(` from beginning of file | |
sed 's/.$//' > "$OUTFILE" # remove `)` from end of file | |
test -e "$BAKFILE" && \ | |
diff -q "$BAKFILE" "$OUTFILE" >/dev/null 2>&1 && \ | |
echo "No changes" || \ | |
echo "Found changes" | |
fi | |
CODE=$(cat <<-EOF | |
.productdata[].country[].interestrates[].section[] | | |
select(.code == "PHL").subsection | # personal home loans only | |
map( | |
select(.code | test("^(FRB|VR)\$")) | # fixed or variable rates only | |
( | |
{ name } + | |
(.baserate | | |
map( | |
select(.code | test("^(FRB[0-3]|VR)I$")) # 0 to 3 years fixed or variable rate only | |
) | | |
map({ | |
rate: .ratevalue|tonumber, | |
type: (if .tiername1 != "" then .tiername1 else .ratename end) | |
})[] | |
) | |
) | |
) | |
EOF | |
) | |
jq "$CODE" "$OUTFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment