mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-01-30 09:48:11 +01:00
Merge latest commits and add retries
This commit is contained in:
parent
e3a5d38200
commit
b1ddd9548e
@ -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 -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
|
getforecast() { curl --retry 5 -sfm 10 "$url/$LOCATION" > "$weatherreport" || exit 1; }
|
||||||
|
|
||||||
# Forecast should be updated only once a day.
|
# Forecast should be updated only once a day.
|
||||||
checkforecast() {
|
checkforecast() {
|
||||||
|
|||||||
@ -5,7 +5,11 @@
|
|||||||
#
|
#
|
||||||
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
|
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
|
||||||
|
|
||||||
ifinstalled "geoip" || exit
|
ifinstalled "geoip" || exit 1
|
||||||
|
|
||||||
ipfile="$XDG_RUNTIME_DIR/iplocate"
|
ipfile="$XDG_RUNTIME_DIR/iplocate"
|
||||||
addr=$(cat "$ipfile") && rm "$ipfile" || { ( curl -s 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" || { ( curl --retry 5 -sfm 10 ifconfig.me > "$ipfile" && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; }
|
||||||
grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//"
|
name="${addr##*, }"
|
||||||
|
flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")"
|
||||||
|
flag="${flag%% *}"
|
||||||
|
printf "%s %s\\n" "$flag" "$name"
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
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 -sf "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; }
|
{ ( curl --retry 5 -sfm 10 "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; }
|
||||||
|
|
||||||
icon="$(cat "$moonfile")"
|
icon="$(cat "$moonfile")"
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1,34 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# price <url> <Name of currency> <icon> <Price to show in (optional)> <dwmblocks signal (optional)>
|
# price <currency-base currency> <name of currency> <icon> <signal>
|
||||||
# price bat "Basic Attention Token" 🦁
|
# price bat-btc "Basic Attention Token" 🦁 24
|
||||||
|
# This will give the price of BAT denominated in BTC and will update on
|
||||||
|
# signal 24.
|
||||||
# When the name of the currency is multi-word, put it in quotes.
|
# When the name of the currency is multi-word, put it in quotes.
|
||||||
|
|
||||||
[ -z "$3" ] && exit 1
|
[ -z "$1" ] && exit 1
|
||||||
|
|
||||||
# handle optional parameters in $4 and/or $5
|
|
||||||
echo "$4" | grep -q '^[0-9]' &&
|
|
||||||
currency='usd' && sig=$4 ||
|
|
||||||
{ currency="${4:-usd}"; sig=$5; }
|
|
||||||
|
|
||||||
url="${CRYPTOURL:-rate.sx}"
|
url="${CRYPTOURL:-rate.sx}"
|
||||||
|
target="${1%%-*}"
|
||||||
|
denom="${1##*-}"
|
||||||
|
name="${2:-$1}"
|
||||||
|
icon="${3:-💰}"
|
||||||
|
case "$denom" in
|
||||||
|
"$target"|usd) denom="usd"; symb="$" ;;
|
||||||
|
gbp) symb="£" ;;
|
||||||
|
eur) symb="€" ;;
|
||||||
|
btc) symb="" ;;
|
||||||
|
esac
|
||||||
interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
|
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/$1-$currency"
|
pricefile="$dir/$target-$denom"
|
||||||
chartfile="$dir/$1-$currency-chart"
|
chartfile="$dir/$target-$denom-chart"
|
||||||
filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
|
filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
|
||||||
|
|
||||||
[ -d "$dir" ] || mkdir -p "$dir"
|
[ -d "$dir" ] || mkdir -p "$dir"
|
||||||
|
|
||||||
updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" ||
|
updateprice() { curl --retry 5 -sfm 10 $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" ||
|
||||||
rm -f "$pricefile" "$chartfile" ;}
|
rm -f "$pricefile" "$chartfile" ;}
|
||||||
|
|
||||||
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
|
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
|
||||||
@ -29,9 +36,9 @@ updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile"
|
|||||||
|
|
||||||
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 "$3 Updating..." "Updating $2 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 "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
|
||||||
notify-send "$3 $2 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.
|
||||||
- Shows 🔃 if updating prices.
|
- Shows 🔃 if updating prices.
|
||||||
@ -42,18 +49,11 @@ esac
|
|||||||
|
|
||||||
[ -n "$updateme" ] &&
|
[ -n "$updateme" ] &&
|
||||||
if [ -n "$showupdate" ]; then
|
if [ -n "$showupdate" ]; then
|
||||||
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now \$$(cat "$pricefile")"
|
updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")"
|
||||||
else
|
else
|
||||||
[ -n "$sig" ] &&
|
[ -n "$4" ] &&
|
||||||
{ ( updateprice "$1" && pkill -RTMIN+"$sig" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } ||
|
{ ( updateprice && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } ||
|
||||||
updateprice "$1"
|
updateprice
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$currency" in
|
[ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")"
|
||||||
usd) symb="$" ;;
|
|
||||||
gbp) symb="£" ;;
|
|
||||||
eur) symb="€" ;;
|
|
||||||
btc) symb="" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")"
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user