Skip to content

Instantly share code, notes, and snippets.

@discarn8
Created May 2, 2018 08:08
Show Gist options
  • Save discarn8/3c1b27f0bff4c78ec8249e4b7f84c959 to your computer and use it in GitHub Desktop.
Save discarn8/3c1b27f0bff4c78ec8249e4b7f84c959 to your computer and use it in GitHub Desktop.
wx_underground_average.sh
#!/bin/bash
# Use this to pull in up to 5 weather stations and grep the temp reading from them. Average only the ones
# that you get dater back from and then dump that to a file. Use Conky to read it or dump it to a db
#
#Change the station id's to valid stations in your area
wAvg=0
wSum=0
n=0
weatherA=0
weatherB=0
weatherC=0
weatherD=0
weatherE=0
weatherA=$(/usr/bin/curl -s "http://stationdata.wunderground.com/cgi-bin/stationlookup?station=station1" | grep -m 1 -o "tempf val=\"[^\"]*\"" | grep -o "\"[^\"]*\." | sed "s/\"//g;s/\.//g")
weatherB=$(/usr/bin/curl -s "http://stationdata.wunderground.com/cgi-bin/stationlookup?station=station2" | grep -m 1 -o "tempf val=\"[^\"]*\"" | grep -o "\"[^\"]*\." | sed "s/\"//g;s/\.//g")
weatherC=$(/usr/bin/curl -s "http://stationdata.wunderground.com/cgi-bin/stationlookup?station=station3" | grep -m 1 -o "tempf val=\"[^\"]*\"" | grep -o "\"[^\"]*\." | sed "s/\"//g;s/\.//g")
weatherD=$(/usr/bin/curl -s "http://stationdata.wunderground.com/cgi-bin/stationlookup?station=station4" | grep -m 1 -o "tempf val=\"[^\"]*\"" | grep -o "\"[^\"]*\." | sed "s/\"//g;s/\.//g")
weatherE=$(/usr/bin/curl -s "http://stationdata.wunderground.com/cgi-bin/stationlookup?station=station5" | grep -m 1 -o "tempf val=\"[^\"]*\"" | grep -o "\"[^\"]*\." | sed "s/\"//g;s/\.//g")
declare -a weather=($weatherA $weatherB $weatherC $weatherD $weatherE)
n=0
for station in "${weather[@]}"; do
if [ ! -z "$station" ]; then
((wSum+=$station))
((n++))
fi
done
let "wAvg = $wSum/$n"
echo $wAvg > ~/wxtemp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment