mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2025-10-07 07:22:36 +02:00
Merge e3e7ef423ad67bd8b155435cc1f8c85ff6b9d329 into 628ed4dc995f3c09e33c24a01c817c18b1a268af
This commit is contained in:
commit
3487abae40
@ -7,11 +7,13 @@ 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() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
|
getforecast() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
|
||||||
|
curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$weatherreport"
|
||||||
|
}
|
||||||
|
|
||||||
# Forecast should be updated only once a day.
|
# Forecast should be updated only once a day.
|
||||||
checkforecast() {
|
checkforecast() {
|
||||||
[ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null |
|
[ "$(stat -c %y "$weatherreport" 2>/dev/null |
|
||||||
cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
|
cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ readfile() { weatherdata="$(cat "$weatherreport")" ;}
|
|||||||
|
|
||||||
showweather() {
|
showweather() {
|
||||||
readfile
|
readfile
|
||||||
|
# shellcheck disable=SC2046,SC2183
|
||||||
printf "☔%s 🥶%s° 🌞%s°\n" "$(getprecipchance)" $(getdailyhighlow)
|
printf "☔%s 🥶%s° 🌞%s°\n" "$(getprecipchance)" $(getdailyhighlow)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +51,15 @@ case $BLOCK_BUTTON in
|
|||||||
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
|
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
checkforecast || getforecast
|
# shellcheck disable=SC2015
|
||||||
|
checkforecast && showweather ||
|
||||||
showweather
|
( flock -n 9 &&
|
||||||
|
( tries=0; while [ $tries -ne 100 ]; do
|
||||||
|
getforecast && break ||
|
||||||
|
{ tries=$((tries+1)); sleep .1; }
|
||||||
|
done
|
||||||
|
! checkforecast &&
|
||||||
|
until getforecast; do sleep 60; done
|
||||||
|
pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}"
|
||||||
|
) &
|
||||||
|
echo ) 9>"${XDG_RUNTIME_DIR}/sb-forecast.lock"
|
||||||
|
|||||||
@ -5,10 +5,25 @@
|
|||||||
#
|
#
|
||||||
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
|
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
|
||||||
|
|
||||||
set -e
|
ifinstalled "geoip" || exit 1
|
||||||
|
|
||||||
ifinstalled "geoip"
|
getip() {
|
||||||
addr="$(geoiplookup "$(curl -sfm 1 ifconfig.me 2>/dev/null)")"
|
{ grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
|
||||||
|
curl -sf api.ipify.org --output "$ipfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
ipfile="$XDG_RUNTIME_DIR/iplocate"
|
||||||
|
addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" ||
|
||||||
|
( flock -n 9 &&
|
||||||
|
( tries=0; while [ $tries -ne 100 ]; do
|
||||||
|
getip && break ||
|
||||||
|
{ tries=$((tries+1)); sleep .1; }
|
||||||
|
done
|
||||||
|
! [ -f "$ipfile" ] &&
|
||||||
|
until getip; do sleep 60; done &&
|
||||||
|
pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}"
|
||||||
|
) &
|
||||||
|
echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-iplocate.lock"
|
||||||
name="${addr##*, }"
|
name="${addr##*, }"
|
||||||
flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")"
|
flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")"
|
||||||
flag="${flag%% *}"
|
flag="${flag%% *}"
|
||||||
|
|||||||
@ -4,8 +4,27 @@
|
|||||||
|
|
||||||
moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase"
|
moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase"
|
||||||
|
|
||||||
[ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
|
checkmoon() {
|
||||||
{ curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;}
|
[ "$(stat -c %y "$moonfile" 2>/dev/null |
|
||||||
|
cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
getmoon() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
|
||||||
|
curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
checkmoon ||
|
||||||
|
( flock -n 9 &&
|
||||||
|
( tries=0; while [ $tries -ne 100 ]; do
|
||||||
|
# shellcheck disable=SC2015
|
||||||
|
getmoon && break ||
|
||||||
|
{ tries=$((tries+1)); sleep .1; }
|
||||||
|
done
|
||||||
|
! checkmoon &&
|
||||||
|
until getmoon; do sleep 60; done
|
||||||
|
pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}"
|
||||||
|
) &
|
||||||
|
echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-moonphase.lock"
|
||||||
|
|
||||||
icon="$(cat "$moonfile")"
|
icon="$(cat "$moonfile")"
|
||||||
|
|
||||||
|
|||||||
@ -24,20 +24,27 @@ interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
|
|||||||
dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices"
|
dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices"
|
||||||
pricefile="$dir/$target-$denom"
|
pricefile="$dir/$target-$denom"
|
||||||
chartfile="$dir/$target-$denom-chart"
|
chartfile="$dir/$target-$denom-chart"
|
||||||
filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
|
|
||||||
|
|
||||||
[ -d "$dir" ] || mkdir -p "$dir"
|
[ -d "$dir" ] || mkdir -p "$dir"
|
||||||
|
|
||||||
updateprice() { curl -sf -m 1 --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" ||
|
checkprice() {
|
||||||
rm -f "$pricefile" "$chartfile" ;}
|
[ "$(stat -c %y "$pricefile" 2>/dev/null |
|
||||||
|
cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
|
||||||
|
}
|
||||||
|
|
||||||
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
|
updateprice() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
|
||||||
updateme="1"
|
curl -sf \
|
||||||
|
--fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \
|
||||||
|
--output "$pricefile" --output "$chartfile" &&
|
||||||
|
touch "$pricefile" "$chartfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
checkprice || updateme="1"
|
||||||
|
|
||||||
case $BLOCK_BUTTON in
|
case $BLOCK_BUTTON in
|
||||||
1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
|
1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
|
||||||
2) notify-send -u low "$icon Updating..." "Updating $name price..." ; updateme="1" ; showupdate="1" ;;
|
2) notify-send -u low "$icon Updating..." "Updating $name price..." ; updateme="1" ; showupdate="1" ;;
|
||||||
3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
|
3) uptime="$(date -d "$(stat -c %x "$pricefile" 2>/dev/null)" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
|
||||||
notify-send "$icon $name module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
|
notify-send "$icon $name 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.
|
||||||
@ -48,9 +55,22 @@ case $BLOCK_BUTTON in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
[ -n "$updateme" ] &&
|
[ -n "$updateme" ] &&
|
||||||
updateprice "$target" &&
|
if [ -n "$showupdate" ]; then
|
||||||
[ -n "$showupdate" ] &&
|
updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")"
|
||||||
notify-send "$icon Update complete." "$name price is now
|
else
|
||||||
\$$(cat "$pricefile")"
|
# shellcheck disable=SC2015
|
||||||
|
[ -n "$4" ] &&
|
||||||
|
( flock -n 9 &&
|
||||||
|
( tries=0; while [ $tries -ne 100 ]; do
|
||||||
|
updateprice && break ||
|
||||||
|
{ tries=$((tries+1)); sleep .1; }
|
||||||
|
done
|
||||||
|
! checkprice &&
|
||||||
|
until updateprice; do sleep 60; done
|
||||||
|
pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}"
|
||||||
|
) &
|
||||||
|
echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-price.lock" ||
|
||||||
|
updateprice
|
||||||
|
fi
|
||||||
|
|
||||||
[ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")"
|
[ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user