85 lines
1.9 KiB
Bash
Executable file
85 lines
1.9 KiB
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
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)
|
|
INFO=$(wget -qO- ipinfo.io)
|
|
CITY=$(echo $INFO | jq -r '.city')
|
|
REGI=$(echo $INFO | jq -r '.region')
|
|
COUN=$(echo $INFO | jq -r '.country')
|
|
QUERY="$CITY, $REGI, $COUN"
|
|
APPID="fd68c0fe7951f5ab7e24a240eb0942b8"
|
|
|
|
http get http://api.openweathermap.org/data/2.5/forecast\?APPID\=${APPID}\&q="${CITY}"\&units\=metric
|
|
}
|
|
|
|
format_weather(){
|
|
case $WEATHER in
|
|
"Clear")
|
|
[ $(date +%H) -gt 06 -a $(date +%H) -lt 18 ] &&
|
|
WEATHER="" ||
|
|
WEATHER=""
|
|
;;
|
|
"Clouds")
|
|
WEATHER=""
|
|
;;
|
|
"Rain"|"Drizzle")
|
|
WEATHER=""
|
|
;;
|
|
"Mist")
|
|
WEATHER=""
|
|
;;
|
|
"Snow")
|
|
WEATHER=""
|
|
;;
|
|
"Thunderstorm")
|
|
WEATHER=""
|
|
;;
|
|
esac
|
|
}
|
|
|
|
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/')
|
|
|
|
text="$MIN $MAX $TEMP°C $WEATHER"
|
|
|
|
echo "$text"
|
|
}
|
|
|
|
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="$WEATHER $TEMP°C"
|
|
|
|
echo "$text"
|
|
}
|
|
|
|
wttrin(){
|
|
local request="wttr.in/${1-Caxias}?QF"
|
|
[ "$(tput cols)" -lt 125 ] && request+='n'
|
|
curl -sH "Accept-Language: ${LANG%_*}" --compressed "$request"
|
|
}
|
|
|
|
if [ "$1" == "full" ]
|
|
then
|
|
wttrin
|
|
elif [ "$1" == "short" ]
|
|
then
|
|
owm_short
|
|
else
|
|
owm_long
|
|
fi
|