Thursday, August 7, 2008

Updated weather script

Since the weather page I used for my previous weather script changed, reducing half of my scripts output to an ascii-splosion, I decided to take another stab at it. Turns out Google supports weather searching. I rewrote the regular expressions and incorporated some new ruby tricks I've learned since. I'm actually rather pleased with the result: weather.rb

The regular expressions are a bit yucky, but that's to be expected. I think the rest of the code is pretty readable. Cool feature: that bit with the join and URI.escape at the top lets you use it like so:

weather san francisco, ca

"san", "francisco,", and "ca" will be passed as separate arguments, but the line at the top will join them together and convert the resulting string into something you could type in a URL bar. (ie: spaces -> %20).

Makes it easy to be sloppy on the command line. :)

No comments: