Skip to content

Instantly share code, notes, and snippets.

@singe
Created May 8, 2018 13:11
Show Gist options
  • Save singe/baac0388fdbb72b4bf650037336af01a to your computer and use it in GitHub Desktop.
Save singe/baac0388fdbb72b4bf650037336af01a to your computer and use it in GitHub Desktop.
A super simple script to pull currency info from xe.com
#!/bin/sh
UA="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15"
url="https://www.xe.com/currencyconverter/convert/"
amount="$1"
fromcur="$2"
tocur="$3"
if [ "$fromcur" == "" ]; then #Use default currencies
fromcur="ZAR"
tocur="GBP"
fi
if [ "$amount" == "-r" ]; then #Reverse default currencies
fromcur="GBP"
tocur="ZAR"
amount="$2"
fi
result=$(wget -U $UA $url/\?Amount\=$amount\&From\=$fromcur\&To\=$tocur -O - 2>/dev/null|grep -o 'uccResultAmount[^<]*'|cut -d\> -f2)
echo $fromcur $amount '->' $tocur $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment