The NOAA’s National Weather Service provides free weather data that you can use on your web site, even if it is for commercial uses. You can’t claim to have copyright on the data, but it is public domain information. Accuweather tried a few years ago to get this service shut down because they wanted people to pay for weather information (which is part of their business). Fortunately people complained because our tax money is being spent on making this data available in the first place.
So why aren’t more people using it? It’s probably because the documentation is daunting, a little confusing and the icons aren’t that great looking. You might be wondering why not just use Yahoo’s Weather RSS feed? Well, because it’s only for non-commercial use and it only gives you current conditions, today’s forecast and tomorrow’s forecast. However once you know how to access NOAA’s data you can customize it to your liking.
It used to be that you had to use the METAR service to get current conditions. METAR is a very unfriendly format and fortunately is no longer necessary. You can now get current conditions in a XML file or RSS file. I recommend using the XML file since you will be able to go through the nodes and format it to your liking. The only key here is that most require an Airport/Airfield nearby, since there are only about 1,800 locations across the United States and US Territories.
Getting Weather Forecasts
The first place to stop is the National Digital Forecast Database XML Web Service. (There are change notices the bottom of the page, but they don’t change very often; however it’s probably a good idea to subscribe to the RSS feed. Then you can make appropriate changes in the future and if there are any new features to the service you can take advantage of them). First thing you’ll notice is that there is a lot of information on this page. The service uses SOAP (basically you make requests with XML and receive XML) and there are two functions to grab the data, NDFDgen and NDFDgenByDay. Both will give you summarized forecasts over a 12 hour or 24 hour time period (your choice). NDFDgen will give you much more information than NDFDgenByDay and lets you pick what you want. You need to know the longitude and latitude of where you want the weather forecast and you can send the number of days you want forecasted. You probably won’t want more than a 7 day forecast. If you want you can even request old weather forecasts. They ask that you cache your results for an hour since that is how often they are updated (even Yahoo’s Weather RSS feed is only updated once an hour). They say they are updated 45 minutes after the hour but from what I’ve seen it’s usually around 52 minutes after the hour. If your web server is on Unix/Linux you can setup a CRON job to grab the files on the hour (although they recommend to do it 15 minutes after the hour, because there is a delay in processing and updating all their files on their servers).
I wish they would offer RSS and XML feeds for some of the bigger cities in the US, rather than just SOAP. Part of me wonders if it is due to pressure from Accuweather and the other US weather sites online, because they have big business in providing easier and prettier methods of weather information. Using SOAP in Coldfusion is pretty simple, especially if you are using Dreamweaver. If you are using PHP, take a look at NuSOAP.