Add btc price tracker panel module
This commit is contained in:
@@ -53,7 +53,7 @@ font-4 = "Font Awesome 5 Brands:pixelsize=16;3"
|
|||||||
|
|
||||||
modules-left = bspwm
|
modules-left = bspwm
|
||||||
modules-center = title
|
modules-center = title
|
||||||
modules-right = pulseaudio backlight-acpi wlan eth battery battery-low date powermenu
|
modules-right = btc pulseaudio backlight-acpi wlan eth battery battery-low date powermenu
|
||||||
|
|
||||||
tray-maxsize = 30
|
tray-maxsize = 30
|
||||||
tray-position = right
|
tray-position = right
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ type = internal/xwindow
|
|||||||
label = %title:0:50:...%
|
label = %title:0:50:...%
|
||||||
label-foreground = ${colors.white-bright}
|
label-foreground = ${colors.white-bright}
|
||||||
|
|
||||||
|
[module/btc]
|
||||||
|
type = custom/script
|
||||||
|
interval = 300
|
||||||
|
|
||||||
|
exec = $HOME/.scripts/panel/btc.sh
|
||||||
|
|
||||||
|
label = %output%
|
||||||
|
label-foreground = ${colors.white-bright}
|
||||||
|
|
||||||
; https://github.com/polybar/polybar/wiki/Module:-pulseaudio
|
; https://github.com/polybar/polybar/wiki/Module:-pulseaudio
|
||||||
[module/pulseaudio]
|
[module/pulseaudio]
|
||||||
type = internal/pulseaudio
|
type = internal/pulseaudio
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ alias vp="$HOME/.scripts/vimplugin.sh"
|
|||||||
alias mpvshuffle="$HOME/.scripts/mpv.sh shuffle"
|
alias mpvshuffle="$HOME/.scripts/mpv.sh shuffle"
|
||||||
|
|
||||||
# Other
|
# Other
|
||||||
|
alias crypto="curl 'https://rate.sx/?qF'"
|
||||||
alias IP="curl https://ifconfig.me"
|
alias IP="curl https://ifconfig.me"
|
||||||
alias len="xclip -o | wc -m"
|
alias len="xclip -o | wc -m"
|
||||||
alias length="rofi -dmenu -i -p 'String length' -lines 0 | tr -d '\n' | wc -m"
|
alias length="rofi -dmenu -i -p 'String length' -lines 0 | tr -d '\n' | wc -m"
|
||||||
|
|||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Enable mathematics in POSIX shell
|
||||||
|
calc() { awk "BEGIN { printf(\"%.2f\", $*) }"; }
|
||||||
|
|
||||||
|
output() {
|
||||||
|
[ -z "$1" ] || [ -z "$2" ] && return 1
|
||||||
|
|
||||||
|
url="$1"
|
||||||
|
price="$2"
|
||||||
|
|
||||||
|
price_old="$(curl -s $url | jq -cr '.data.amount')"
|
||||||
|
difference=$(calc "$price / $price_old * 100 - 100")
|
||||||
|
|
||||||
|
# Get symbol and color
|
||||||
|
old_higher=$(calc "$price < $price_old" | cut -c 1)
|
||||||
|
if [ $old_higher -eq 0 ]; then
|
||||||
|
symbol=""
|
||||||
|
color="$COLOR2"
|
||||||
|
else
|
||||||
|
symbol=""
|
||||||
|
color="$COLOR1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Result
|
||||||
|
echo "%{F$color}$symbol $difference%%{F$COLOR15}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get dates
|
||||||
|
date_yesterday="$(date -d 'yesterday' +'%Y-%m-%d')"
|
||||||
|
date_last_week="$(date -d 'last week' +'%Y-%m-%d')"
|
||||||
|
|
||||||
|
# Get API URLs
|
||||||
|
url="https://api.coinbase.com/v2/prices/BTC-USD/spot"
|
||||||
|
url_yesterday="${url}?date=$date_yesterday"
|
||||||
|
url_last_week="${url}?date=$date_last_week"
|
||||||
|
|
||||||
|
# Current price
|
||||||
|
price="$(curl -s $url | jq -cr '.data.amount')"
|
||||||
|
|
||||||
|
# Create output formatting
|
||||||
|
difference_yesterday_output="d $(output $url_yesterday $price)"
|
||||||
|
difference_last_week_output="w $(output $url_last_week $price)"
|
||||||
|
|
||||||
|
echo "\$$price $difference_yesterday_output $difference_last_week_output"
|
||||||
Reference in New Issue
Block a user