Fixed the weather module since wunderground is broken.
This commit is contained in:
parent
511faf83f8
commit
c43ba1f8f4
@ -1,16 +1,36 @@
|
|||||||
[ -f functions.sh ] && source functions.sh
|
[ -f functions.sh ] && source functions.sh
|
||||||
|
|
||||||
set -f
|
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 '<tr><td>Temperature</td>' | tr -cd '[:digit:]-.')"
|
|
||||||
weatherConditions="$(echo "$weatherInfo" | grep -A 1 '<tr><td>Conditions</td>' | 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
|
name="$1"
|
||||||
weatherInfo="Sorry $1, no weather found for $3."
|
channelName="$2"
|
||||||
fi
|
shift
|
||||||
msg "$2" "$1: $weatherInfo"
|
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
|
set +f
|
||||||
|
Loading…
x
Reference in New Issue
Block a user