mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
fix(theme): fix glowsticks using broken websites
This commit is contained in:
parent
1cba8edfc3
commit
4dabb892db
|
@ -102,62 +102,75 @@ blocks:
|
||||||
properties:
|
properties:
|
||||||
script: |
|
script: |
|
||||||
api_key="$OWM_API_KEY" # change this
|
api_key="$OWM_API_KEY" # change this
|
||||||
now=$(date +'%I:%M')
|
location='$LOCATION' # change this (or dont, and set the variable in your env)
|
||||||
[[ $(date +'%p') == 'am' ]] && now+='滛 ' || now+=' '
|
|
||||||
echo -n "$now"
|
set -e
|
||||||
[[ -z $api_key ]] && exit 0
|
|
||||||
update=$(jq '.minute' /tmp/weather.w | tr -d '"')
|
now="$(date +'%I:%M%P')"
|
||||||
if [[ -f '/tmp/weather.w' && $NO_WEATHER_CACHE -ne 1 && $(bc -l <<<"$(date +'%M')<=($update+10)") -eq 1 ]]; then
|
|
||||||
echo -n "$(jq .weather /tmp/weather.w | tr -d '"')" && exit 0
|
if [[ -f /tmp/weather.w && $NO_WEATHER_CACHE -ne 1 ]]; then
|
||||||
else
|
update=$(jq '.minute' /tmp/weather.w | tr -d '"')
|
||||||
location=$(curl -m .25 -s 'https://freegeoip.live/json/')
|
# refresh every ten minutes
|
||||||
[[ $? -ne 0 ]] && echo -n '(睊)' && exit 0
|
if [[ $(bc -l <<<"$(date +'%M')<=($update+10)") -eq 1 ]]; then
|
||||||
url="https://api.openweathermap.org/data/2.5/weather?lat=$(echo "$location" | jq .latitude)&lon=$(echo "$location" | jq .longitude)&units=metric&appid=$api_key"
|
echo "$now" "$(jq .weather /tmp/weather.w | tr -d '"')" && exit 0
|
||||||
res=$(curl -m .25 -s "$url")
|
fi
|
||||||
[[ $? -ne 0 ]] && echo -n '(睊)' && exit 0
|
|
||||||
temp=$(echo "$res" | jq .main.temp)
|
|
||||||
temp_min=$(echo "$res" | jq .main.temp_min)
|
|
||||||
temp_max=$(echo "$res" | jq .main.temp_max)
|
|
||||||
[[ $(bc -l <<<"$temp_min!=$temp") -eq 1 ]] && temp_min_s="$temp_min-"
|
|
||||||
[[ $(bc -l <<<"$temp_max==$temp") -eq 1 ]] && temp_s="$temp_min_s$temp糖" || temp_s+="(${temp_min}${temp}-${temp_max})糖"
|
|
||||||
feels_like=$(echo "$res" | jq .main.feels_like)
|
|
||||||
[[ $(bc -l <<<"$feels_like!=$temp_min&&$feels_like!=$temp&&$feels_like!=$temp_max") -eq 1 ]] && feels_string="feels $feels_like糖"
|
|
||||||
case $(echo "$res" | jq .weather[0].icon | tr -d '"') in
|
|
||||||
01n | 01d)
|
|
||||||
icon='\ufa98'
|
|
||||||
;;
|
|
||||||
02n | 02d)
|
|
||||||
icon='\ufa94'
|
|
||||||
;;
|
|
||||||
03n | 03d)
|
|
||||||
icon='\ue33d'
|
|
||||||
;;
|
|
||||||
04n | 04d)
|
|
||||||
icon='\ue312'
|
|
||||||
;;
|
|
||||||
09n | 09d)
|
|
||||||
icon='\ufa95'
|
|
||||||
;;
|
|
||||||
10n | 10d)
|
|
||||||
icon='\ue308'
|
|
||||||
;;
|
|
||||||
11n | 11d)
|
|
||||||
icon='\ue31d'
|
|
||||||
;;
|
|
||||||
13n | 13d)
|
|
||||||
icon='\ue31a'
|
|
||||||
;;
|
|
||||||
50n | 50d)
|
|
||||||
icon='\ue313'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
icon=''
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
weather="${icon} ${temp_s} ${feels_string}"
|
|
||||||
echo -ne "$weather"
|
|
||||||
echo -ne "{\"minute\": \"$(date +'%M')\", \"weather\": \"$weather\"}" >/tmp/weather.w
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
gurl="curl -Gsm.7 https://api.openweathermap.org"
|
||||||
|
enc="--data-urlencode"
|
||||||
|
|
||||||
|
# get location
|
||||||
|
[[ ! -f /tmp/location.w ]] &&
|
||||||
|
$gurl/geo/1.0/direct $enc "q=$location" $enc "limit=0" $enc "appid=$api_key" | jq -c '{"lat": .[0].lat, "lon": .[0].lon}' >/tmp/location.w
|
||||||
|
location="$(cat /tmp/location.w)"
|
||||||
|
|
||||||
|
# get weather
|
||||||
|
res=$($gurl/data/2.5/weather $enc "lat=$(jq .lat <<<"$location")" $enc "lon=$(jq .lon <<<"$location")" $enc "units=metric" $enc "appid=$api_key")
|
||||||
|
temp=$(jq .main.temp <<<"$res")
|
||||||
|
temp_min=$(jq .main.temp_min <<<"$res")
|
||||||
|
temp_max=$(jq .main.temp_max <<<"$res")
|
||||||
|
[[ $(bc -l <<<"$temp_min!=$temp") -eq 1 ]] && temp_min_s="$temp_min-"
|
||||||
|
[[ $(bc -l <<<"$temp_max==$temp") -eq 1 ]] && temp_s="$temp_min_s$temp°C" || temp_s+="(${temp_min}${temp}-${temp_max})°C"
|
||||||
|
feels_like=$(jq .main.feels_like <<<"$res")
|
||||||
|
[[ $(bc -l <<<"$feels_like!=$temp_min&&$feels_like!=$temp&&$feels_like!=$temp_max") -eq 1 ]] && feels_string="feels $feels_like°C"
|
||||||
|
|
||||||
|
# pick weather icon
|
||||||
|
case $(jq .weather[0].icon <<<"$res" | tr -d '"') in
|
||||||
|
01n | 01d)
|
||||||
|
icon='\ufa98'
|
||||||
|
;;
|
||||||
|
02n | 02d)
|
||||||
|
icon='\ufa94'
|
||||||
|
;;
|
||||||
|
03n | 03d)
|
||||||
|
icon='\ue33d'
|
||||||
|
;;
|
||||||
|
04n | 04d)
|
||||||
|
icon='\ue312'
|
||||||
|
;;
|
||||||
|
09n | 09d)
|
||||||
|
icon='\ufa95'
|
||||||
|
;;
|
||||||
|
10n | 10d)
|
||||||
|
icon='\ue308'
|
||||||
|
;;
|
||||||
|
11n | 11d)
|
||||||
|
icon='\ue31d'
|
||||||
|
;;
|
||||||
|
13n | 13d)
|
||||||
|
icon='\ue31a'
|
||||||
|
;;
|
||||||
|
50n | 50d)
|
||||||
|
icon='\ue313'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
icon=''
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
weather="$icon - $temp_s $feels_string"
|
||||||
|
echo -e "$now $weather"
|
||||||
|
echo -e "{\"minute\": \"$(date +'%M')\", \"weather\": \"$weather\"}" >/tmp/weather.w
|
||||||
|
|
||||||
style: diamond
|
style: diamond
|
||||||
template: "{{ .Output }}"
|
template: "{{ .Output }}"
|
||||||
trailing_diamond:
|
trailing_diamond:
|
||||||
|
|
Loading…
Reference in a new issue