#!/bin/sh # # Grab weather data from weather.com and format it according to the given XSLT # Script written by boojit # Modified by Hellf[i]re # The orignal script and xslt can be downloaded from http://pondol.com/weather.tar.gz # Usage: # ${execi 1800 /path/to/weather/weather.sh location} # Usage Example: # ${execi 1800 /home/user/weather/weather.sh 03833} # your Location ID: use http://xoap.weather.com/search/search?where=[yourcity] to find it # U.S. users can just use their zip code; doubt that works for anyone else though (YMMV) LOCID=$1 # s=standard units, m=metric units UNITS=m # where this script and the XSLT lives RUNDIR=/home/hellfire/scripts/weather # there's probably other stuff besides CURL that will work for this, but i haven't # tried any others. # you can get curl at http://curl.haxx.se/ CURLCMD=/usr/bin/curl # get it at http://xmlsoft.org/XSLT/ XSLTCMD=/usr/bin/xsltproc # you probably don't need to modify anything below this point.... # CURL url. Use cc=* for current forecast or dayf=10 to get a multi-day forecast CURLURL="http://xoap.weather.com/weather/local/$LOCID?cc=*&unit=$UNITS&dayf=2" # The XSLT to use when translating the response from weather.com # You can modify this xslt to your liking XSLT=$RUNDIR/weather.xslt #filter (if you want to convert stuff to lower-case or upper case or something) #FILTER="|gawk '{print(tolower(\$0));}'" ##### eval "$CURLCMD \"$CURLURL\" 2>/dev/null| $XSLTCMD $XSLT - $FILTER" localhost% cat /usr/bin/weather.py ~/conkyscripts/weather #!/usr/bin/python -tt # -*- coding: iso-8859-15 -*- __version__="1.0"import pymetar import sys #print "pymet v%s using pymetar lib v%s"%(__version__,pymetar.__version__) if len(sys.argv)<2 or sys.argv[1]=="--help": sys.stderr.write("Usage: %s \n"% sys.argv[0]) sys.stderr.write("Station IDs can be found at: http://www.nws.noaa.gov/tg/siteloc.shtml\n") sys.exit(1) elif (sys.argv[1] == "--version"): print "pmw v%s using pymetar lib v%s"%(__version__,pymetar.__version__) sys.exit(0) else: station=sys.argv[1] try: rf=pymetar.ReportFetcher(station) rep=rf.FetchReport() except Exception, e: sys.stderr.write("Something went wrong when fetching the report.\n") sys.stderr.write("These usually are transient problems if the station ") sys.stderr.write("ID is valid. \nThe error encountered was:\n") sys.stderr.write(str(e)+"\n") sys.exit(1) rp=pymetar.ReportParser() pr=rp.ParseReport(rep) print "Weather report for %s (%s) as of %s" %\ (pr.getStationName(), station, pr.getISOTime()) print "Values of \"None\" indicate that the value is missing from the report." print "Temperature: %s C / %s F" %\ (pr.getTemperatureCelsius(), pr.getTemperatureFahrenheit()) print "Rel. Humidity: %s%%" % (pr.getHumidity()) if pr.getWindSpeed() is not None: print "Wind speed: %0.2f m/s" % (pr.getWindSpeed()) else: print "Wind speed: None" print "Wind direction: %s deg (%s)" %\ (pr.getWindDirection(), pr.getWindCompass()) if pr.getPressure() is not None: print "Pressure: %s hPa" % (int(pr.getPressure())) else: print "Pressure: None" print "Dew Point: %s C / %s F" %\ (pr.getDewPointCelsius(), pr.getDewPointFahrenheit()) print "Weather:",pr.getWeather() print "Sky Conditions:",pr.getSkyConditions()