Skip to content

Instantly share code, notes, and snippets.

@logie17
Created April 10, 2013 06:03
Show Gist options
  • Select an option

  • Save logie17/5352170 to your computer and use it in GitHub Desktop.

Select an option

Save logie17/5352170 to your computer and use it in GitHub Desktop.
Weather Proxy via Python
#! /usr/bin/env python
import urllib, cgi, random, string
cgi_params = cgi.FieldStorage()
lat = cgi_params.getvalue('lat') or '42.3265152'
lon = cgi_params.getvalue('lon') or '-122.87559490000001'
unit = cgi_params.getvalue('unit') or 0
lg = cgi_params.getvalue('lg') or 'english'
fcst = cgi_params.getvalue('fcsttype') or 'dwml'
#nocache = "".join( [random.choice(string.digits) for i in xrange(8)] )
nocache = 123
params = urllib.urlencode({'lat': lat, 'lon':lon, 'unit':unit, 'lg': lg, 'FcstType': fcst, 'nocache': nocache})
response = urllib.urlopen("http://forecast.weather.gov/MapClick.php?%s" % params)
print "Content-Type: application/xml"
print response.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment