Skip to content

Instantly share code, notes, and snippets.

@avioli
Created September 29, 2016 22:54
Show Gist options
  • Save avioli/097b3e78b984d3f8fe99b8d335c6fa90 to your computer and use it in GitHub Desktop.
Save avioli/097b3e78b984d3f8fe99b8d335c6fa90 to your computer and use it in GitHub Desktop.
A basic fetcher for ANZ bank loan rates
#!/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&section=&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