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-26 05:23:47 +01:00
|
|
|
INFO=$(wget -qO- ipinfo.io)
|
2019-12-18 01:36:42 +01:00
|
|
|
CITY=$(echo $INFO | jq -r '.city')
|
|
|
|
REGI=$(echo $INFO | jq -r '.region')
|
|
|
|
COUN=$(echo $INFO | jq -r '.country')
|
|
|
|
QUERY="$CITY, $REGI, $COUN"
|
2019-12-05 20:48:20 +01:00
|
|
|
APPID="fd68c0fe7951f5ab7e24a240eb0942b8"
|
2019-12-02 19:57:45 +01:00
|
|
|
|
2020-01-10 04:16:50 +01:00
|
|
|
FORECAST=$(http get http://api.openweathermap.org/data/2.5/forecast\?APPID\=${APPID}\&q="${CITY}"\&units\=metric)
|
|
|
|
TEMP=$(echo $FORECAST | jq -r ".list[0].main.temp")
|
|
|
|
WEATHER=$(echo $FORECAST | jq -r ".list[0].weather[0].main")
|
|
|
|
|
|
|
|
format_weather
|
2019-12-09 19:25:42 +01:00
|
|
|
}
|
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")
|
2020-03-13 03:13:31 +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(){
|
2020-01-10 04:16:50 +01:00
|
|
|
owm
|
2019-12-09 19:25:42 +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/')
|
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(){
|
2020-01-10 04:16:50 +01:00
|
|
|
owm
|
2019-12-09 19:25:42 +01:00
|
|
|
|
2019-12-13 05:20:24 +01:00
|
|
|
text="$WEATHER $TEMP°C"
|
2019-12-09 19:25:42 +01:00
|
|
|
|
|
|
|
echo "$text"
|
|
|
|
}
|
|
|
|
|
2020-01-10 04:16:50 +01:00
|
|
|
owm_pango(){
|
|
|
|
owm
|
|
|
|
|
|
|
|
text="$WEATHER <b>$TEMP°C</b>"
|
|
|
|
|
|
|
|
echo "$text"
|
|
|
|
}
|
|
|
|
|
2019-12-09 19:25:42 +01:00
|
|
|
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
|
2020-01-10 04:16:50 +01:00
|
|
|
elif [ "$1" == "pango" ]
|
|
|
|
then
|
|
|
|
owm_pango
|
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
|