mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-01-30 09:48:11 +01:00
Make the retry logic better + other changes
This commit is contained in:
parent
b7dc644e1a
commit
de863bf0f0
@ -7,7 +7,7 @@ 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 --retry 5 -sfm 10 "$url/$LOCATION" > "$weatherreport" || exit 1; }
|
getforecast() { curl -sf "$url/$LOCATION" > "$weatherreport"; }
|
||||||
|
|
||||||
# Forecast should be updated only once a day.
|
# Forecast should be updated only once a day.
|
||||||
checkforecast() {
|
checkforecast() {
|
||||||
@ -38,7 +38,7 @@ showweather() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case $BLOCK_BUTTON in
|
case $BLOCK_BUTTON in
|
||||||
1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;;
|
1) setsid -f "$TERMINAL" -e less -Sf "$weatherreport" ;;
|
||||||
2) getforecast && showweather ;;
|
2) getforecast && showweather ;;
|
||||||
3) notify-send "🌈 Weather module" "\- Left click for full forecast.
|
3) notify-send "🌈 Weather module" "\- Left click for full forecast.
|
||||||
- Middle click to update forecast.
|
- Middle click to update forecast.
|
||||||
@ -48,4 +48,9 @@ case $BLOCK_BUTTON in
|
|||||||
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
checkforecast && showweather || { ( getforecast && pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}") & echo; }
|
checkforecast && showweather ||
|
||||||
|
{ [ -z "$(pgrep 'sb-forecast' | tail -n +3)" ] &&
|
||||||
|
( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } &&
|
||||||
|
getforecast; do sleep 60; done &&
|
||||||
|
pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}" ) &
|
||||||
|
echo; }
|
||||||
|
|||||||
@ -8,7 +8,12 @@
|
|||||||
ifinstalled "geoip" || exit 1
|
ifinstalled "geoip" || exit 1
|
||||||
|
|
||||||
ipfile="$XDG_RUNTIME_DIR/iplocate"
|
ipfile="$XDG_RUNTIME_DIR/iplocate"
|
||||||
addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || { ( curl --retry 5 -sfm 10 ifconfig.me > "$ipfile" && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; }
|
addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" ||
|
||||||
|
{ [ -z "$(pgrep 'sb-iplocate' | tail -n +3)" ] &&
|
||||||
|
( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } &&
|
||||||
|
curl -sf ifconfig.me > "$ipfile"; do sleep 60; done &&
|
||||||
|
pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) &
|
||||||
|
echo; exit; }
|
||||||
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%% *}"
|
||||||
|
|||||||
@ -5,7 +5,11 @@
|
|||||||
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')" ] ||
|
[ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
|
||||||
{ ( curl --retry 5 -sfm 10 "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; }
|
{ [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] &&
|
||||||
|
( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } &&
|
||||||
|
curl -sf "wttr.in/?format=%m" > "$moonfile"; do sleep 60; done &&
|
||||||
|
pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) &
|
||||||
|
echo; exit; }
|
||||||
|
|
||||||
icon="$(cat "$moonfile")"
|
icon="$(cat "$moonfile")"
|
||||||
|
|
||||||
|
|||||||
@ -28,8 +28,7 @@ filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
|
|||||||
|
|
||||||
[ -d "$dir" ] || mkdir -p "$dir"
|
[ -d "$dir" ] || mkdir -p "$dir"
|
||||||
|
|
||||||
updateprice() { curl --retry 5 -sfm 10 --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" ||
|
updateprice() { curl -sf --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile"; }
|
||||||
rm -f "$pricefile" "$chartfile" ;}
|
|
||||||
|
|
||||||
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
|
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
|
||||||
updateme="1"
|
updateme="1"
|
||||||
@ -52,7 +51,11 @@ esac
|
|||||||
updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")"
|
updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")"
|
||||||
else
|
else
|
||||||
[ -n "$4" ] &&
|
[ -n "$4" ] &&
|
||||||
{ ( updateprice && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } ||
|
{ [ -z "$(pgrep 'sb-price' | tail -n +3)" ] &&
|
||||||
|
( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } &&
|
||||||
|
updateprice; do sleep 60; done &&
|
||||||
|
pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) &
|
||||||
|
echo; exit; } ||
|
||||||
updateprice
|
updateprice
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user