2016-09-09 14:39:47 -04:00
|
|
|
[ -f functions.sh ] && source functions.sh
|
|
|
|
|
2017-04-03 17:59:44 -04:00
|
|
|
set -f
|
2016-09-09 14:39:47 -04:00
|
|
|
|
2018-07-31 16:57:32 -04:00
|
|
|
name="$1"
|
|
|
|
channelName="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
|
2020-07-30 03:51:56 -04:00
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
msg "$channelName" "$name: Please provide a location or postcode."
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
location="${*}"
|
|
|
|
|
|
|
|
# Convert spaces to +.
|
|
|
|
location="${location//[[:space:]]/+}"
|
|
|
|
|
|
|
|
|
|
|
|
# c Weather condition,
|
|
|
|
# C Weather condition textual name,
|
|
|
|
# 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
|
2020-08-10 20:23:56 -04:00
|
|
|
message+="Wind: ${weatherInfo[w]} "
|
2020-07-30 03:51:56 -04:00
|
|
|
if [[ "${weatherInfo[p]}" != "0.0mm" ]]; then
|
|
|
|
message+=" Precipitation: ${weatherInfo[p]} "
|
|
|
|
fi
|
|
|
|
if [[ -n "${weatherInfo[o]}" ]]; then
|
|
|
|
message+="Chance of precipitation ${weatherInfo[o]} "
|
|
|
|
fi
|
2020-07-30 20:43:17 -04:00
|
|
|
message+="Humidity: ${weatherInfo[h]}. "
|
2020-07-30 03:51:56 -04:00
|
|
|
message+="Sunrise: ${weatherInfo[S]}, Sunset: ${weatherInfo[s]}."
|
|
|
|
|
|
|
|
msg "$channelName" "$name: ${message//+/ }"
|