Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ######################################################################
- #Copyright (C) 2024 Kris Occhipinti
- #https://filmsbykris.com
- #This program is free software: you can redistribute it and/or modify
- #it under the terms of the GNU General Public License as published by
- #the Free Software Foundation version 3 of the License.
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #You should have received a copy of the GNU General Public License
- #along with this program. If not, see <http://www.gnu.org/licenses/>.
- ######################################################################
- # this will get the current bitcoin value in USD
- # Note that there is a limit of requests that can be made to the API
- # so we will make sure we don't check more then once a minute
- url="https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
- bittime="/tmp/bittime.log"
- bitvalue="/tmp/bitvalue.log"
- normal=$(echo -en "\e[0m")
- red=$(echo -en "\e[31m")
- green=$(echo -en "\e[32m")
- # Make sure it's been at least 60 seconds
- currenttime="$(date +%s)"
- lasttime=0
- [[ -f $bittime ]] && lasttime="$(head -n 1 $bittime)"
- timediff=$(( $currenttime - $lasttime ))
- if [[ $timediff -lt 60 ]]
- then
- #If it has been less then 60 seconds
- # show last value in red
- printf "${red}"
- cat $bitvalue
- exit
- fi
- #log current time to file
- echo $currenttime > $bittime
- # fetch and print current value in green
- value="$(wget -qO- "$url"|jq '.bitcoin.usd')"
- printf "$%'d\n" $value > $bitvalue
- printf "${green}$%'d\n" $value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement