September 1, 2004

Retrieving local weather

At work, we have one primary line-of-business application called PLUS. Depending on your groups in Active Directory, portions of the application are enabled for you. For example, the business licensing portion isn't enabled for someone who primarily handles street work orders.

Maintaining a monolithic application like this may be a bit of a headache, but we have a few advantages. First, anyone can go to any desktop in the city, log in, and work. Second, security is handled at the domain level, so giving someone rights only has to be done once, and they're taken care of on our Intranet site as well as in PLUS. Third, we're able to reuse a lot of functionality within the application. Finally, since auto-update functionality has been built-in, when we get new features for departments or bug fixes, we simply prop the new build to our server, and each client pulls down the new version.

Recently, one of our department goals has been to reduce the amount of spyware and adware coming into the city. We use Spybot: Search & Destroy, Ad-Aware and SpywareBlaster to get rid of the spyware. One piece of adware we see nearly everywhere in the city, however, is WeatherBug.

Now, we can't really blame people for wanting to keep abreast of the weather, so we decided to write the weather check functionality into PLUS.

We have a form that updates a set of shared members once an hour using an XML feed from NOAA that I found out about from Ali Aghareza's blog. I don't bother with any sort of parsing, and my only validation is to check to see if the .weather member of my structure is equal to String.Empty. However, it works, and is fairly speedy.

WeatherXMLURL is set in our Globals. Currently, it's set to "http://www.nws.noaa.gov/data/current_obs/KHIF.xml".

Module modWeather


Public Structure WeatherInfo
Dim weather, temp, wind, pressure, visibility, windchill, humidity As String
End Structure

Public Function GetWeather() As WeatherInfo
Try
Dim d As New Xml.XmlDocument
d.Load(WeatherXMLURL)
Dim w As WeatherInfo
With w
.weather = d.SelectSingleNode("/current_observation/weather").InnerText
.temp = d.SelectSingleNode("/current_observation/temperature_string").InnerText
.wind = d.SelectSingleNode("/current_observation/wind_string").InnerText
.pressure = d.SelectSingleNode("/current_observation/pressure_string").InnerText
.visibility = d.SelectSingleNode("/current_observation/visibility").InnerText
.windchill = d.SelectSingleNode("/current_observation/windchill_string").InnerText
.humidity = d.SelectSingleNode("/current_observation/relative_humidity").InnerText
End With
Return w
Catch ex As Exception
Trace.WriteLine(ex.Message, "Weather")
Trace.WriteLine(ex.StackTrace, "Weather")
Return New WeatherInfo
End Try
End Function

End Module

No comments: