2022-10-28 15:26:00 +03:00
|
|
|
#!/usr/bin/env bash
|
2022-06-06 23:13:59 +03:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-06-15 10:48:00 +03:00
|
|
|
curl_opts=(--silent --connect-timeout 1 --no-progress-meter -X GET)
|
|
|
|
|
2022-06-06 23:13:59 +03:00
|
|
|
curl_cbr () {
|
|
|
|
local today=$(date +%d/%m/%Y)
|
2023-01-08 15:28:29 +03:00
|
|
|
local start_range=$(date +%d/%m/%Y -d '-14 day')
|
2022-06-06 23:13:59 +03:00
|
|
|
local usd=R01235
|
|
|
|
|
2023-06-15 10:48:00 +03:00
|
|
|
curl ${curl_opts[@]} "https://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=$start_range&date_req2=$today&VAL_NM_RQ=$usd" | \
|
2022-06-06 23:13:59 +03:00
|
|
|
sed -e "s/<[A-Z]/\n\0/g" | \
|
|
|
|
grep Value | \
|
|
|
|
sed -e "s#<\/\?\w\+>##g" | \
|
|
|
|
sed -e "s/,/./g"
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_exchangerate () {
|
|
|
|
local start_date=$(date +%Y-%m-%d -d '-1 day')
|
|
|
|
local end_date=$(date +%Y-%m-%d)
|
|
|
|
|
2023-06-15 10:48:00 +03:00
|
|
|
curl ${curl_opts[@]} "https://api.exchangerate.host/timeseries?start_date=$start_date&end_date=$end_date&base=USD&symbols=RUB&places=4&format=xml" | \
|
2022-06-06 23:13:59 +03:00
|
|
|
sed -e "s/<[a-z]/\n\0/g" | \
|
|
|
|
grep rate | \
|
|
|
|
sed -e "s#<\/\?\w\+>##g"
|
|
|
|
}
|
|
|
|
|
2023-01-08 15:28:29 +03:00
|
|
|
res=($(curl_cbr))
|
|
|
|
if [ -z "$res" ]; then
|
2023-06-15 11:09:09 +03:00
|
|
|
text="NO DATA"
|
2023-06-15 11:18:44 +03:00
|
|
|
echo "%{F@error@}${text}%{F-}"
|
2023-01-08 15:28:29 +03:00
|
|
|
exit 0
|
|
|
|
fi
|
2022-06-06 23:13:59 +03:00
|
|
|
|
2023-01-08 15:28:29 +03:00
|
|
|
diff=$(echo ${res[-1]} ${res[-2]} | awk '{ print $1 - $2 }')
|
2022-06-06 23:13:59 +03:00
|
|
|
arror="↑"
|
2022-10-28 15:26:00 +03:00
|
|
|
color='@success@'
|
2022-06-06 23:13:59 +03:00
|
|
|
if [ ${diff:0:1} == '-' ]; then
|
|
|
|
diff=${diff:1}
|
|
|
|
arror="↓"
|
2022-10-28 15:26:00 +03:00
|
|
|
color='@error@'
|
2022-06-06 23:13:59 +03:00
|
|
|
fi
|
|
|
|
|
2023-06-15 11:09:09 +03:00
|
|
|
echo "${res[-1]} (%{F${color}}${arror}%{O3}${diff}%{F-})"
|
2022-06-06 23:13:59 +03:00
|
|
|
exit 0
|
|
|
|
|