updated the weather module.
This commit is contained in:
parent
c4fc8c308e
commit
e9d92da650
@ -7,30 +7,67 @@ channelName="$2"
|
|||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Get the current weather information into a variable and stip all blank lines.
|
if [[ $# -eq 0 ]]; then
|
||||||
args="$@"
|
msg "$channelName" "$name: Please provide a location or postcode."
|
||||||
weather="$(curl -s http://wttr.in/${args//[[:space:]]/+}?T0 | sed '/^$/d')"
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the location
|
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
|
# Convert spaces to +.
|
||||||
conditions="${weather%* }"
|
location="${location//[[:space:]]/+}"
|
||||||
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.
|
# c Weather condition,
|
||||||
msg "$channelName" "$name: weather for ${location} is ${conditions} and ${temperature}."
|
# C Weather condition textual name,
|
||||||
set +f
|
# h Humidity,
|
||||||
|
# t Temperature (Actual),
|
||||||
|
# f Temperature (Feels Like),
|
||||||
|
# w Wind,
|
||||||
|
# l Location,
|
||||||
|
# m Moonphase ðð,
|
||||||
|
# M Moonday,
|
||||||
|
# p precipitation (mm),
|
||||||
|
# o Probability of Precipitation,
|
||||||
|
# P pressure (hPa),
|
||||||
|
|
||||||
|
# D Dawn*,
|
||||||
|
# S Sunrise*,
|
||||||
|
# z Zenith*,
|
||||||
|
# s Sunset*,
|
||||||
|
# d Dusk*.
|
||||||
|
|
||||||
|
format="%c|%C|%h|%t|%f|%w|%l|%m|%M|%p|%o|%P|%D|%S|%z|%s|%d"
|
||||||
|
argList="${format//%/}"
|
||||||
|
argList="${argList//|/ }"
|
||||||
|
weatherString="$(curl -s https://wttr.in/${location}?format="${format}")"
|
||||||
|
|
||||||
|
i=1
|
||||||
|
declare -A weatherInfo
|
||||||
|
for j in $argList ; do
|
||||||
|
weatherInfo[$j]="$(echo "${weatherString}" | cut -d '|' -f $i)"
|
||||||
|
((i++))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Format times to 12 hour format.
|
||||||
|
for i in S D z s d ; do
|
||||||
|
weatherInfo[$i]="$(date '+%r' --date="${weatherInfo[$i]}")"
|
||||||
|
done
|
||||||
|
|
||||||
|
message="${weatherInfo[l]}: ${weatherInfo[t]} and ${weatherInfo[C]}"
|
||||||
|
if [[ "${weatherInfo[t]}" == "${weatherInfo[f]}" ]]; then
|
||||||
|
message+=". "
|
||||||
|
else
|
||||||
|
message+=" with a real feel of ${weatherInfo[f]}. "
|
||||||
|
fi
|
||||||
|
message+="Wind: ${weatherInfo[w]}"
|
||||||
|
if [[ "${weatherInfo[p]}" != "0.0mm" ]]; then
|
||||||
|
message+=" Precipitation: ${weatherInfo[p]} "
|
||||||
|
fi
|
||||||
|
if [[ -n "${weatherInfo[o]}" ]]; then
|
||||||
|
message+="Chance of precipitation ${weatherInfo[o]} "
|
||||||
|
fi
|
||||||
|
message+=" Humidity: ${weatherInfo[h]}. "
|
||||||
|
message+="Sunrise: ${weatherInfo[S]}, Sunset: ${weatherInfo[s]}."
|
||||||
|
|
||||||
|
msg "$channelName" "$name: ${message//+/ }"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user