From c43ba1f8f4cfd07a0e6d9a1c8d3cea0713facdcb Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 31 Jul 2018 16:57:32 -0400 Subject: [PATCH] Fixed the weather module since wunderground is broken. --- modules/weather/weather.sh | 42 ++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/modules/weather/weather.sh b/modules/weather/weather.sh index 997ce9b..225dd53 100755 --- a/modules/weather/weather.sh +++ b/modules/weather/weather.sh @@ -1,16 +1,36 @@ [ -f functions.sh ] && source functions.sh set -f -if [ ${#3} -ge 5 ]; then -weatherInfo="$(curl -s "http://mobile.wunderground.com/cgi-bin/findweather/getForecast?brand=mobile&query=$3")" -weatherTemperature="$(echo "$weatherInfo" | grep -A 2 'Temperature' | tr -cd '[:digit:]-.')" -weatherConditions="$(echo "$weatherInfo" | grep -A 1 'Conditions' | tail -n1 | sed 's/<[^>]*>//g')" -weatherConditions="${weatherConditions/*Rain/wetter than a teenage girl at a boy band concert}" -weatherInfo="Currently your weather is $weatherConditions and $weatherTemperature degrees fahrenheit." -fi -if [ ${#weatherInfo} -lt 5 ]; then -weatherInfo="Sorry $1, no weather found for $3." -fi -msg "$2" "$1: $weatherInfo" +name="$1" +channelName="$2" +shift +shift + +# Get the current weather information into a variable and stip all blank lines. +args="$@" +weather="$(curl -s http://wttr.in/${args//[[:space:]]/+}?T0 | sed '/^$/d')" + +# Get the location +location="$(echo "$weather" | head -n1 | cut -f2 -d: | sed 's/^[[:space:]]//')" +# Strip location info from the weather variable +weather="${weather#*$'\n'}" + +# Extract current conditions from the weather variable +conditions="${weather%* }" +conditions="${conditions%%$'\n'*}" +conditions="${conditions##* }" +# Remove conditions info from weather variable. +# Also remove everything after the next line because we only need the temperature info. +weather="${weather#*$'\n'}" +weather="${weather%%$'\n'*}" + +# Get and format the temperature information from the weather variable. +temperature="${weather##*. }" +temperature="${temperature##*-}" +# Remove leading and trailing spaces. +temperature="$(echo "$temperature" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + +# Show the weather information. +msg "$channelName" "$name: weather for ${location} is ${conditions} and ${temperature}." set +f