In anticipation/excitement of my gear ariving (thanks beamerbob/ad72!), I went ahead and wrote a script that pulls local weather conditions from
wunderground's PWS api and plugged it into something called geektool which is like active desktop for OSX. Nothing about the script itself is OS
Specific so it should work on windows. That being said, I don't use windows, so I don't know off the top of my head to embed it into a windows
desktop. Nonetheless, I thought I'd share it with you guys, in case theres some other OSX geeks here that may find it useful.
I literally wrote this in 10 minutes, so it's neither robust nor particularly novel. That being said, its been working for me!
Code: |
#!/usr/bin/python
import urllib2
import json
import time
import sys
HEADINGS = {
0 : 'N',
1 : 'NNE',
2 : 'E',
3 : 'SSE',
4 : 'S',
5 : 'SSW',
6 : 'W',
7 : 'NNW',
}
def getStationCurrentStatus(stationID):
url = "http://stationdata.wunderground.com/cgi-bin/stationlookup?station=%s&format=json"
resp = json.load(urllib2.urlopen(url % stationID))
return resp.get('conds').get(stationID)
def degToDir(deg):
deg = round((deg)/45) % 8
return HEADINGS[deg]
def main():
if len(sys.argv) <= 1:
return
recentData = getStationCurrentStatus(sys.argv[1])
if recentData is None:
return
speed = float(recentData['windspeedmph'])
gust = float(recentData['windgustmph'])
print "Wind: %0.1f / %0.1f MPH" % (speed, gust)
if gust != 0:
print "Quality: %0.1f" % (speed/gust)
print "Dir: %s" % degToDir(int(recentData['winddir']))
lastUpdated = time.time()-float(recentData['lu'])
print "(%0.1f sec ago)" % (lastUpdated)
main()
|
Run it with your favorite PWS station ID from wunderground... as an example:
Code: |
./windinfo.py KCASANFR79
Wind: 1.7 / 3.5 MPH
Quality: 0.5
Dir: SSE
(2.3 sec ago)
|
Just drop it into geektool and you have continuously updating wind/gust/direction info for your favorite PWS
Looks like this on my desktop:
(Note that for my local PWS, gust seems to be broken as it always reads the same as avg wind speed)
15m PL Charger II / 19m FS Speed 3 DLX / 13m PL Venom 1 / 9m HQ Montana 7 / 3m HQ Scout III / Trampa Holy Pro 15° /MBS Comp 90