Skip to content
Snippets Groups Projects
Commit 941b9f94 authored by rs11g21's avatar rs11g21
Browse files

Able to handle error if received undesired status code

parent bf33fa48
Branches
No related tags found
No related merge requests found
#! /usr/bin/bash
#------------Date--------------------------
if [ "$(curl -s -o /dev/null -w "%{http_code}" https://www.coindesk.com/price/bitcoin/)" -eq "200" ]; then
echo "Coin Desk is ready for data collection"
dateCollected=$(date +"%Y-%m-%d")
timeCollected=$(date +"%T")
dateTime="$dateCollected $timeCollected"
printf "Date Time : %s" "$dateTime"
#------------Bit Coin Price----------------
address=$(curl -s https://www.coindesk.com/price/bitcoin/)
bitCoinValue=$( echo $address | grep -o "<span class=\"currency-pricestyles__Price-sc-1rux8hj-0 eEpEzP\">.*<\/span>" 2> /dev/null | sed 's/\(<span class=\"currency-pricestyles__Price-sc-1rux8hj-0 eEpEzP\">\|<\/span>\)/\n/g' | head -n 2| sed 's/,//g')
printf "\nBitCoin Value : %s"$bitCoinValue;
#printf "\n"
#-------------Bit Coin 24H Low--------------
hour_24_low=$(echo $address | grep -o '<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<\/span>//g' | sed -E 's/\$|,|N\/A|M|B//g' | grep -v '^$' | head -n 1)
printf "\nBitCoin 24 Hour Low : %s"$hour_24_low;
#printf "\n"
#-------------Bit Coin 24H High-------------
hour_24_high=$(echo $address | grep -o '<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<\/span>//g' | sed -E 's/\$|,|N\/A|M|B//g' | grep -v '^$' | head -n 2 | tail -n 1)
printf "\nBitCoin 24 Hour High : %s"$hour_24_high;
#printf "\n"
#-------------Bit Coin 24H Open-------------
hour_24_open=$(echo $address | grep -o '<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<\/span>//g' | sed -E 's/\$|,|N\/A|M|B//g' | grep -v '^$' | head -n 3 | tail -n 1)
printf "\nBitCoin 24 Hour Open : %s"$hour_24_open;
#printf "\n"
#-------------Bit Coin Market Cap-------------
market_cap=$(echo $address | curl -s https://www.coindesk.com/price/bitcoin/ | grep -o '<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<\/span>//g' | sed -E 's/\$|,|N\/A|M|B//g' | grep -v '^$' | head -n 7 | tail -n 1)
printf "\nBitCoin Market Cap : %s"$market_cap;
#printf "\n"
#------------Bit Coin Change------------------
changesInValue=$(echo $address | grep -o '\(<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\)[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\|<\/span>//g'| sed -E 's/\$|,|N\/A|M|%|B//g' | grep -v '^$' | head -n 4 | tail -n 1);
printf "\nBitCoin Change In Value : %s"$changesInValue;
#printf "\n"
#------------Bit Coin Return------------------
returnPercentage=$(echo $address | grep -o '\(<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\)[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\|<\/span>//g'| sed -E 's/\$|,|N\/A|M|%|B//g' | grep -v '^$' | head -n 8 | tail -n 1);
printf "\nBitCoin Return Percentage : %s"$returnPercentage;
#printf "\n"
#----------- Bit Coin Volatility--------------
volatility=$(echo $address | grep -o '\(<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\)[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\|<\/span>//g'| sed -E 's/\$|,|N\/A|M|%|B//g' | grep -v '^$' | tail -n 3 | head -n 1);
printf "\nBitCoin Volatility : %s"$volatility;
#printf "\n"
#----------- Bit Coin 24 H Transanction Count--------------
transactionCount=$(echo $address | grep -o '\(<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\)[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\|<\/span>//g'| sed -E 's/\$|,|N\/A|M|%|B//g' | grep -v '^$' | tail -n 2 | head -n 1);
printf "\nBitCoin 24 H Transaction Count: %s"$transactionCount;
#printf "\n"
#----------- Bit Coin 24 H Average Transaction Fee --------------
transactionFee=$(echo $address | grep -o '\(<span class=\"typography__StyledTypography-owin6q-0 gqNskB\">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\)[^<]*</span>' | sed 's/<span class=\"typography__StyledTypography-owin6q-0 gqNskB">\|<span class=\"typography__StyledTypography-owin6q-0 jrTwew">\|<\/span>//g'| sed -E 's/\$|,|N\/A|M|%|B//g' | grep -v '^$' | tail -n 1);
printf "\nBitCoin Transaction Fee : %s"$transactionFee;
printf "\n"
else
echo "Coin Desk is not ready for data collection. Status code failed"
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment