BeautifulSoup - Get A 10 Day Weather Forecast For Your Zip Code
|
After Matt Harrison mentioned BeautifulSoup in a comment to an old Python script post of mine, I've been looking for somewhere where I could use it. |
BeautifulSoup is a Python HTML/XML parser designed for quick turnaround projects like screen-scraping.
I initially played around with it, seeing if I could use it to get listings of when new episodes of my favorite TV programs were appearing, now that Zap2It Labs are no longer making their listing available for free. The problem there (I think) is that, because of the dynamically generated content on their TV listings website, I can't find a URL that BeautifulSoup can parse.
So I picked something different to cut my teeth on.
I often go to Weather.com and get a 10 day forecast for the city where I live. Easy to do, but I used this as an example of something to extract from a web page and then also email it to me so I have it handy.
This script does this. You will also need to get a copy of BeautifulSoup.py for it to work properly. I've simply put them both in the same directory and run it with:
$ python ./get_weather.py
If others are interested in running this, then there are two variables that you will need to change in the script to meet your needs:
# Zip code to get 10 day forecast for. # zipCode = "94024" # Email address to sent results to. # emailAddr = "someone@somewhere.com"
Just like my early attempts with using XPath in some of my JavaScript scripts, I suspect that I'm not doing it the best way.I predict that there are much nicer ways of writing the extractForecast() routine.
Still it works and that's the first step in programming.
[Technorati Tag: BeautifulSoup]
( Apr 30 2008, 08:58:05 AM PDT ) [Listen] Permalink Comments [5]
Airplane Flights Patterns Over The USA
|
|
A cool movie today from the APOD (Astronomy Picture of the Day) folks. |
The movie depicts flight patterns that occurred over a few days in 2005 March. The count on the lower left shows the number of USA-related flights at the time listed on the lower right.
The major cities are beacons of light and the eastern seaboard just blazes at certain times of the day.
An excellent way of presenting the data.
( Apr 30 2008, 08:01:21 AM PDT ) [Listen] Permalink Comments [1]













