This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/scripts/.local/bin/forecast

57 lines
1.3 KiB
Plaintext
Raw Normal View History

2019-10-16 02:28:41 +02:00
#!/bin/sh
2019-12-01 17:36:00 +01:00
set -e
2019-10-16 02:28:41 +02:00
2019-12-05 20:48:20 +01:00
short(){
CITY=$(curl -s ipinfo.io/city)
APPID="fd68c0fe7951f5ab7e24a240eb0942b8"
FORECAST=$(http get http://api.openweathermap.org/data/2.5/forecast\?APPID\=${APPID}\&q\="${CITY}"\&units\=metric)
2019-12-02 19:57:45 +01:00
2019-12-05 20:48:20 +01:00
TEMP=$(echo $FORECAST | jq -r ".list[0].main.temp")
WEATHER=$(echo $FORECAST | jq -r ".list[0].weather[0].main")
2019-10-16 02:28:41 +02:00
2019-12-05 20:48:20 +01:00
MIN=$(echo $FORECAST | jq -r ".list[2].main.temp_min" |
perl -pe 's/(\d*)\.\d*/\1/')
MAX=$(echo $FORECAST | jq -r ".list[2].main.temp_max" |
perl -pe 's/(\d*)\.\d*/\1/')
case $WEATHER in
"Clear")
WEATHER=" "
;;
"Clouds")
WEATHER=" "
;;
"Rain"|"Drizzle")
WEATHER=" "
;;
"Mist")
WEATHER=" "
;;
"Snow")
WEATHER=" "
;;
"Thunderstorm")
WEATHER=""
;;
esac
text="$MIN $MAX $TEMP°C $WEATHER"
# tooltip="$(curl -s wttr.in | paste -d'\\n' -s )"
tooltip=""
echo "$text"
}
full(){
local request="wttr.in/${1-Caxias}"
[ "$(tput cols)" -lt 125 ] && request+='?n'
curl -sH "Accept-Language: ${LANG%_*}" --compressed "$request" |
head -n-3 | tail -n+3
}
if [ "$1" == "full" ]
then
full
else
short
fi