Skip to content

Commit

Permalink
Put the location-specific stuff at the top with instructions for cust…
Browse files Browse the repository at this point in the history
…omization.
  • Loading branch information
drdrang committed Apr 27, 2011
1 parent b7269b8 commit 9217ed1
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions weather.cgi
@@ -1,12 +1,28 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# These are the items that can be customized for a different location.
# The zipcode is just the 5-digit code; no need for extensions.
# The station can be found by going to
# http://www.weather.gov/xml/current_obs/seek.php?state=il&Find=Find
# and choosing the closest NOAA station for your state.
# The radar image can be found at http://weather.com by searching
# on your location and then following the "Classic Map" link. Use
# the URL of that image here.
zipcode = '60502'
station = 'KARR'
radar = 'http://i.imwx.com/web/radar/us_ord_ultraradar_plus_usen.jpg'


# The code below shouldn't be modified unless you want to change the layout
# or the type of data presented.

import pywapi
import datetime
import re

import cgitb
cgitb.enable()
# import cgitb
# cgitb.enable()

# The date and time as a string. Note: My host's server is on Eastern Time
# and I'm on Central Time, so I subtract an hour.
Expand All @@ -17,8 +33,8 @@ now = re.sub(r' 0(\d )', r' \1', now) # day has a space before and after
now = re.sub(r'0(\d:)', r'\1', now) # hour has a colon after

# Get the current conditions for the given station.
noaa = pywapi.get_weather_from_noaa('KARR')
yahoo = pywapi.get_weather_from_yahoo('60502', '')
noaa = pywapi.get_weather_from_noaa(station)
yahoo = pywapi.get_weather_from_yahoo(zipcode, '')

# Interpretation of the Yahoo pressure dictionary.
ypressure = {'0': 'steady', '1': 'rising', '2': 'falling'}
Expand Down Expand Up @@ -67,7 +83,7 @@ content += 'Pressure: %s and %s<br />\n' % (float(yahoo['atmosphere']['pressure'

content += 'Sunlight: %s to %s</p>\n' % (yahoo['astronomy']['sunrise'], yahoo['astronomy']['sunset'])

content += '<p><img width="100%" src="http://i.imwx.com/web/radar/us_ord_ultraradar_plus_usen.jpg" /></p>\n'
content += '<p><img width="100%%" src="%s" /></p>\n' % radar

content += '''<h1>Today</h1>
<p>High: %s&deg;<br />
Expand Down

0 comments on commit 9217ed1

Please sign in to comment.