summaryrefslogtreecommitdiffstats
path: root/.local
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2023-03-20 09:50:18 -0400
committerLuke Smith <luke@lukesmith.xyz>2023-03-20 09:50:18 -0400
commitfd964d54b6bfaab35304543c61cf2209e4fa1430 (patch)
tree3a61fec78f1e2f95560c1d9870c294f3185a0ffc /.local
parent37930fdf573c4834e080c4a2ea94706c5465071c (diff)
downloadeibhear-fd964d54b6bfaab35304543c61cf2209e4fa1430.tar.gz
eibhear-fd964d54b6bfaab35304543c61cf2209e4fa1430.tar.zst
eibhear-fd964d54b6bfaab35304543c61cf2209e4fa1430.zip
customizable wttr/rate urls, sb-price improvements
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/statusbar/sb-forecast3
-rwxr-xr-x.local/bin/statusbar/sb-price21
2 files changed, 12 insertions, 12 deletions
diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast
index 2a6440b..2b41b3d 100755
--- a/.local/bin/statusbar/sb-forecast
+++ b/.local/bin/statusbar/sb-forecast
@@ -3,10 +3,11 @@
# Displays today's precipication chance (☔), and daily low (🥶) and high (🌞).
# Usually intended for the statusbar.
+url="${WTTRURL:-wttr.in}"
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
# 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.
checkforecast() {
diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price
index 42c84c1..53c5023 100755
--- a/.local/bin/statusbar/sb-price
+++ b/.local/bin/statusbar/sb-price
@@ -8,21 +8,20 @@
[ -z "$3" ] && exit 1
# use $4 as currency, if not passed in use "usd" as default
+url="${CRYPTOURL:-rate.sx}"
currency="${4:-usd}"
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"
chartfile="$dir/$1-$currency-chart"
-
-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" ;}
+filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
[ -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"
case $BLOCK_BUTTON in
@@ -30,7 +29,7 @@ case $BLOCK_BUTTON in
2) notify-send -u low "$3 Updating..." "Updating $2 price..."
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
\$$(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>
- Left click for chart of changes.
- Middle click to update.
@@ -44,7 +43,7 @@ case "$currency" in
usd) symb="$" ;;
gbp) symb="£" ;;
eur) symb="€" ;;
- btc) symb="₿" ;;
+ btc) symb="" ;;
esac
-printf "$3$symb%0.2f$after" "$(cat "$pricefile")"
+[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")"