Weather Underground Web API using C#, Part 1

In the off hours, I’ve been teaching myself C#…a simple enough object oriented language, with the benefit of using the .NET framework. If you’re targeting Windows, it’s incredibly easy…features like file IO and serial port communications work effortlessly.

I have a list of tasks that I complete before I refer to myself as ‘capable’ in a new language:

  • Helloworld
  • Web API Access
  • File IO
  • XML Parsing
  • GUI Creation
  • Serial Communication
  • System Call
  • Directory Management
  • Database Connectivity
  • 3rd Party Library Integration
  • Error Catching/Mitigation
  • Logging

I complete some of the above by using C# to access the Weather Underground’s API, and pull down current weather information for places I’ve lived. If you’re looking to use this code, you’ll have to go to the API website and request a key.

Helloworld
Using Visual Studio Express 2012 create a new console application. I added some lines to frame the start and end of the program.

0

Parse XML
I create a method called ‘parse’ that performs the following:

  1. Takes a Wunderground query URL (e.g. “http://api.wunderground.com/api/YOUR_KEY/conditions/q/VA/Springfield.xml”) as input
  2. Requests the data from Wunderground.
  3. Parses the XML file for pertinent weather data.
  4. Prints the data out to the console.

1

Output
Below is a screenshot of weather data for five different places I’ve lived…

results

Full Code
Full project file for Visual Studio can be found here: Wunderground_API_Test.

Leave a Reply