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

82 lines
1.7 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-09 19:25:42 +01:00
owm(){
# IPINFO=$(curl -s ipinfo.io/loc)
# LAT=$(echo $IPINFO | cut -d, -f1 | cut -d. -f1)
# LON=$(echo $IPINFO | cut -d, -f2 | cut -d. -f1)
2019-12-05 20:48:20 +01:00
CITY=$(curl -s ipinfo.io/city)
APPID="fd68c0fe7951f5ab7e24a240eb0942b8"
2019-12-02 19:57:45 +01:00
2019-12-09 19:25:42 +01:00
http get http://api.openweathermap.org/data/2.5/forecast\?APPID\=${APPID}\&q="${CITY}"\&units\=metric
}
2019-10-16 02:28:41 +02:00
2019-12-09 19:25:42 +01:00
format_weather(){
2019-12-05 20:48:20 +01:00
case $WEATHER in
"Clear")
2019-12-13 03:25:15 +01:00
[ $(date +%H) -gt 06 -a $(date +%H) -lt 18 ] &&
WEATHER="" ||
WEATHER=""
2019-12-05 20:48:20 +01:00
;;
"Clouds")
2019-12-13 03:25:15 +01:00
WEATHER=""
2019-12-05 20:48:20 +01:00
;;
"Rain"|"Drizzle")
2019-12-13 03:25:15 +01:00
WEATHER=""
2019-12-05 20:48:20 +01:00
;;
"Mist")
2019-12-13 03:25:15 +01:00
WEATHER=""
2019-12-05 20:48:20 +01:00
;;
"Snow")
2019-12-13 03:25:15 +01:00
WEATHER=""
2019-12-05 20:48:20 +01:00
;;
"Thunderstorm")
WEATHER=""
;;
esac
2019-12-09 19:25:42 +01:00
}
owm_long(){
FORECAST=$(owm)
TEMP=$(echo $FORECAST | jq -r ".list[0].main.temp")
WEATHER=$(echo $FORECAST | jq -r ".list[0].weather[0].main")
format_weather
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/')
2019-12-05 20:48:20 +01:00
text="$MIN $MAX $TEMP°C $WEATHER"
2019-12-09 19:25:42 +01:00
2019-12-05 20:48:20 +01:00
echo "$text"
}
2019-12-09 19:25:42 +01:00
owm_short(){
FORECAST=$(owm)
TEMP=$(echo $FORECAST | jq -r ".list[0].main.temp" |
perl -pe 's/(\d*)\.\d*/\1/')
WEATHER=$(echo $FORECAST | jq -r ".list[0].weather[0].main")
format_weather
text="$TEMP°C $WEATHER"
echo "$text"
}
wttrin(){
local request="wttr.in/${1-Caxias}?QF"
[ "$(tput cols)" -lt 125 ] && request+='n'
curl -sH "Accept-Language: ${LANG%_*}" --compressed "$request"
2019-12-05 20:48:20 +01:00
}
if [ "$1" == "full" ]
then
2019-12-09 19:25:42 +01:00
wttrin
elif [ "$1" == "short" ]
then
owm_short
2019-12-05 20:48:20 +01:00
else
2019-12-09 19:25:42 +01:00
owm_long
2019-12-05 20:48:20 +01:00
fi