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/dotfiles/scripts/forecast

115 lines
2.1 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-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"
APPID=`_pass_get OpenWeatherMapAPPID`
2020-10-20 22:55:27 +02:00
#{%@@ if False @@%}#
notify-send "Get a free appid"
xdg-open openweathermap.org &
exit 1
#{%@@ endif @@%}#
2019-12-02 19:57:45 +01:00
2020-07-02 07:35:52 +02:00
FORECAST=$(wget -qO- http://api.openweathermap.org/data/2.5/forecast\?APPID\=${APPID}\&q="${CITY}"\&units\=metric)
2020-03-29 19:42:58 +02:00
TEMP=$(echo $FORECAST | jq -r ".list[0].main.temp" |
perl -pe 's/(\d*)\.\d*/\1/')
2020-01-10 04:16:50 +01:00
WEATHER=$(echo $FORECAST | jq -r ".list[0].weather[0].main")
2020-03-29 19:42:58 +02: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/')
2020-01-10 04:16:50 +01:00
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")
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-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"
}
2020-03-29 19:42:58 +02:00
owm_json(){
owm
2020-06-17 10:25:10 +02:00
tee > .forecast.json <<EOF
2020-07-02 07:35:52 +02:00
{
2020-03-29 19:42:58 +02:00
"min":"$MIN",
"max":"$MAX",
"temp":"$TEMP",
"weather":"$WEATHER"
}
EOF
}
2019-12-09 19:25:42 +01:00
wttrin(){
2021-02-13 15:26:13 +01:00
curl -s --compressed "v2.wttr.in"
2019-12-05 20:48:20 +01:00
}
2020-06-17 10:25:10 +02:00
case "$1" in
short)
owm_short;;
pango)
owm_pango;;
json)
owm_json;;
long)
owm_long;;
2020-10-10 07:43:28 +02:00
interactive)
clear
wttrin
read -n1 -p"Press any key to quit..." ;;
2020-06-17 10:25:10 +02:00
full|*)
wttrin;;
esac