Power Kite Forum

Trivial Current Wind Conditions Tracker

SpecialK - 16-4-2014 at 09:21 AM

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)

dangerdan - 16-4-2014 at 10:15 AM

GeekTool is an application for Mac OS 10.6+ according to Google

SpecialK - 16-4-2014 at 10:20 AM

Yep! Works fine in 10.9 Mavericks.

hardstatic - 21-4-2014 at 08:44 PM

This is very cool, thanks for sharing. Works like a champ!

SpecialK - 22-4-2014 at 07:47 AM

Awesome! I'm glad someone else got some use out of it!