This has been me off and on the past couple of days:
Playing with bash and the wunderground api.
Jeremy Pope (jpope)'s status on Sunday, 02-Sep-12 10:13:33 CDT - micro.jpope.org
Matrix bots have been providing me with a few weather details ever since I set that StatusNet instance up. I have a little bash script that will pull the data on a set schedule via cron. Previously, I had been using google's "secret" weather api as it pulled quickly, is easily parsed, didn't require an account and had just the few details that I wanted. Judging from the error message I get when attempting to open the xml feed in my browser, they've blocked my IP and or domain:
So, now it was time to find another place to pull from. I prefer to pull from an api as opposed to scraping a page somewhere. I really hate having a script fail due to the page being scraped changing something in it's layout. In the past, my first stop would have been weather.com but, they made some changes a while back and no longer have a free api to hit. So, my first (and only) stop this time was wunderground.com. I haven't visited the Wunderground site much but, have been seeing it referenced more and more lately. Plus, I have an interest in getting a personal weather station eventually, which can report to Wunderground if desired.
It turns out, Wunderground has a free api (after signing up) that is quite extensive (at least compared to the google feed) and very well documented. The script that I had to pull the weather was just parsing xml and it was quick and easy to change to the Wunderground api.
Ooooh, a current radar now. :D
I also decided that I'd also like for a little forecast as well. Not a full, multi day forecast but, just an outlook of the next few hours or so. Was quite easy with the Wunderground api actually.
Most likely, there are much easier ways to parse the xml or json feeds returned by the api but, I stuck to good ol' bash. Examples of the scripts that I ended up with can be found here: current conditions and forecast. Both of these have a few options at the start of the scripts. Also, the forecast script will pull multiple forecasts, although, only one at a time. Check the top "readme" section on the script. Also, for the embedded images, I'm fairly certain that you'll need the Textile plugin active on your instance.
And now that I've been playing with Wunderground the past couple of days, I *really * like it. It'll most likely be my first stop for looking at weather info on the net from now on.
(well, aside from my bots that is...)
Now that I know for certain what the weather is going to be like, I'm heading outside. ;)