Created
November 19, 2017 15:56
-
-
Save putnamhill/3c3e08baca6d6a6d66b06c2a89c02480 to your computer and use it in GitHub Desktop.
Reads the coinmarketcap ticker and writes the prices for a cryptocoins to a file
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
#!/bin/bash | |
get_data() { | |
# if the parameter is a local file just cat it (for testing) otherwise try curl | |
{ test -r "$1" && cat "$1" || curl -s "$1"; } | \ | |
jq --raw-output \ | |
'.[] | "\(.symbol | ascii_downcase) \(.price_usd)"' | |
} | |
process() { | |
read -r filename price <<< $(get_data "$1") | |
printf "\$filename: %s\t\$price: %.2f\n" "$filename" "$price" | |
#echo "$price" > "$filename" | |
} | |
if [ ${#} -gt 0 ]; then # read urls from args on the command line if there are any | |
while [ ${#} -gt 0 ]; do | |
url="$1" | |
shift | |
process "$url" | |
done | |
else # read urls from stdin | |
while read -r url; do | |
process "$url" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment