customizable wttr/rate urls, sb-price improvements
This commit is contained in:
parent
37930fdf57
commit
fd964d54b6
3 changed files with 16 additions and 12 deletions
|
@ -16,6 +16,10 @@ export TERMINAL="st"
|
||||||
export TERMINAL_PROG="st"
|
export TERMINAL_PROG="st"
|
||||||
export BROWSER="librewolf"
|
export BROWSER="librewolf"
|
||||||
|
|
||||||
|
# Change the default crypto/weather monitor sites.
|
||||||
|
# export CRYPTOURL="rate.sx"
|
||||||
|
# export WTTRURL="wttr.in"
|
||||||
|
|
||||||
# ~/ Clean-up:
|
# ~/ Clean-up:
|
||||||
export XDG_CONFIG_HOME="$HOME/.config"
|
export XDG_CONFIG_HOME="$HOME/.config"
|
||||||
export XDG_DATA_HOME="$HOME/.local/share"
|
export XDG_DATA_HOME="$HOME/.local/share"
|
||||||
|
|
|
@ -3,10 +3,11 @@
|
||||||
# Displays today's precipication chance (☔), and daily low (🥶) and high (🌞).
|
# Displays today's precipication chance (☔), and daily low (🥶) and high (🌞).
|
||||||
# Usually intended for the statusbar.
|
# Usually intended for the statusbar.
|
||||||
|
|
||||||
|
url="${WTTRURL:-wttr.in}"
|
||||||
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
|
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
|
||||||
|
|
||||||
# Get a weather report from 'wttr.in' and save it locally.
|
# Get a weather report from 'wttr.in' and save it locally.
|
||||||
getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1; }
|
getforecast() { curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
|
||||||
|
|
||||||
# Forecast should be updated only once a day.
|
# Forecast should be updated only once a day.
|
||||||
checkforecast() {
|
checkforecast() {
|
||||||
|
|
|
@ -8,21 +8,20 @@
|
||||||
[ -z "$3" ] && exit 1
|
[ -z "$3" ] && exit 1
|
||||||
|
|
||||||
# use $4 as currency, if not passed in use "usd" as default
|
# use $4 as currency, if not passed in use "usd" as default
|
||||||
|
url="${CRYPTOURL:-rate.sx}"
|
||||||
currency="${4:-usd}"
|
currency="${4:-usd}"
|
||||||
interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
|
interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
|
||||||
dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
|
dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices"
|
||||||
pricefile="$dir/$1-$currency"
|
pricefile="$dir/$1-$currency"
|
||||||
chartfile="$dir/$1-$currency-chart"
|
chartfile="$dir/$1-$currency-chart"
|
||||||
|
filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
|
||||||
updateprice() { temp="$(mktemp)"
|
|
||||||
curl -s "$currency.rate.sx/1$1" > "$temp" &&
|
|
||||||
mv -f "$temp" "$pricefile" &&
|
|
||||||
curl -s "$currency.rate.sx/$1$interval" > "$temp" &&
|
|
||||||
mv -f "$temp" "$chartfile" ;}
|
|
||||||
|
|
||||||
[ -d "$dir" ] || mkdir -p "$dir"
|
[ -d "$dir" ] || mkdir -p "$dir"
|
||||||
|
|
||||||
[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
|
updateprice() { curl -sf -m 3 $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" ||
|
||||||
|
rm -f "$pricefile" "$chartfile" ;}
|
||||||
|
|
||||||
|
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
|
||||||
updateprice "$1"
|
updateprice "$1"
|
||||||
|
|
||||||
case $BLOCK_BUTTON in
|
case $BLOCK_BUTTON in
|
||||||
|
@ -30,7 +29,7 @@ case $BLOCK_BUTTON in
|
||||||
2) notify-send -u low "$3 Updating..." "Updating $2 price..."
|
2) notify-send -u low "$3 Updating..." "Updating $2 price..."
|
||||||
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
|
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
|
||||||
\$$(cat "$pricefile")" ;;
|
\$$(cat "$pricefile")" ;;
|
||||||
3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
|
3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
|
||||||
notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
|
notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
|
||||||
- Left click for chart of changes.
|
- Left click for chart of changes.
|
||||||
- Middle click to update.
|
- Middle click to update.
|
||||||
|
@ -44,7 +43,7 @@ case "$currency" in
|
||||||
usd) symb="$" ;;
|
usd) symb="$" ;;
|
||||||
gbp) symb="£" ;;
|
gbp) symb="£" ;;
|
||||||
eur) symb="€" ;;
|
eur) symb="€" ;;
|
||||||
btc) symb="₿" ;;
|
btc) symb="" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
printf "$3$symb%0.2f$after" "$(cat "$pricefile")"
|
[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")"
|
||||||
|
|
Loading…
Reference in a new issue