users/wm: fix exchangerate script

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-08 15:28:29 +03:00
parent 661672eecb
commit 7ffb027147
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215

View file

@ -4,10 +4,10 @@ set -e
curl_cbr () {
local today=$(date +%d/%m/%Y)
local prev_week=$(date +%d/%m/%Y -d '-7 day')
local start_range=$(date +%d/%m/%Y -d '-14 day')
local usd=R01235
curl --no-progress-meter "https://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=$prev_week&date_req2=$today&VAL_NM_RQ=$usd" | \
curl --no-progress-meter "https://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=$start_range&date_req2=$today&VAL_NM_RQ=$usd" | \
sed -e "s/<[A-Z]/\n\0/g" | \
grep Value | \
sed -e "s#<\/\?\w\+>##g" | \
@ -27,9 +27,13 @@ curl_exchangerate () {
# bar_name=xmobar
bar_name=polybar
cc=($(curl_cbr))
res=($(curl_cbr))
if [ -z "$res" ]; then
echo NO DATA
exit 0
fi
diff=$(echo ${cc[-1]} ${cc[-2]} | awk '{ print $1 - $2 }')
diff=$(echo ${res[-1]} ${res[-2]} | awk '{ print $1 - $2 }')
arror="↑"
color='@success@'
if [ ${diff:0:1} == '-' ]; then
@ -40,11 +44,11 @@ fi
case $bar_name in
"xmobar")
echo "${cc[-1]} (<fc=${color}>${arror}<hspace=3/>${diff}</fc>)"
echo "${res[-1]} (<fc=${color}>${arror}<hspace=3/>${diff}</fc>)"
;;
"polybar")
echo "${cc[-1]} (%{F${color}}${arror}%{O3}${diff}%{F-})"
echo "${res[-1]} (%{F${color}}${arror}%{O3}${diff}%{F-})"
;;
esac