Weather Office Screen Scraper
This is quite out of date and no longer works with the layout used on the Weather Office website.
Weather Office recently added RSS feeds to their site:
http://www.weatheroffice.gc.ca/mainmenu/faq_e.html#rss
Weather Office recently added RSS feeds to their site:
http://www.weatheroffice.gc.ca/mainmenu/faq_e.html#rss
About
A Python screen scraper for retrieving the current conditions and text forecast from Environment Canada'sWeather Office site.
Requirements
BeautifulSoupDownload
weatheroffice.py (Version 1.1, Thu Jul 7 16:28:42 PDT 2005)
Examples
Get the current conditions:
>>> import weatheroffice
>>> weather = weatheroffice.parse('http://weatheroffice.ec.gc.ca/city/pages/on-143_metric_e.html')
>>> weather.conditions_observed
"Observed at: Toronto Pearson Int'l Airport 29 January 2005 3:00 PM EST"
>>> for condition, value in weather.conditions.items():
... print '%s: %s' % (condition, value)
...
Pressure: 102.6 kPa falling
Temperature: -2 °C
Dewpoint: -8 °C
Visibility: 24 km
Humidity: 62 %
Wind: S 8 km/h
Get the forecast:
>>> import weatheroffice
>>> weather = weatheroffice.parse('http://weatheroffice.ec.gc.ca/city/pages/on-143_metric_e.html')
>>> weather.forecast_issued
'Toronto: Issued 3.30 PM EST Saturday 29 January 2005'
>>> for day, forecast in weather.forecast:
... print '%s: %s' % (day, forecast)
...
Tonight: Cloudy. Low minus 9.
Sunday: A mix of sun and cloud. Wind northeast 20 km/h becoming light in the afternoon. High minus 3.
Monday: Sunny. Low minus 14. High minus 4.
Tuesday: A mix of sun and cloud. Low minus 12. High minus 2.
Wednesday: A mix of sun and cloud. Low minus 12. High minus 1.
Using Last-Modified to save bandwidth:
>>> import weatheroffice
>>> weather = weatheroffice.parse('http://weatheroffice.ec.gc.ca/city/pages/on-143_metric_e.html')
>>> weather.last_modified
'Sun, 30 Jan 2005 23:02:35 GMT'
>>> weather2 = weatheroffice.parse('http://weatheroffice.ec.gc.ca/city/pages/on-143_metric_e.html', \
... last_modified=weather.last_modified)
>>> weather2.status
304
>>> weather2.forecast
[]
>>> weather2.conditions
{}