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:
- Web API Access
- File IO
- XML Parsing
- GUI Creation
- Serial Communication
- System Call
- Directory Management
- Database Connectivity
- 3rd Party Library Integration
- Error Catching/Mitigation
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.
Using Visual Studio Express 2012 create a new console application. I added some lines to frame the start and end of the program.
I create a method called ‘parse’ that performs the following:
- Takes a Wunderground query URL (e.g. “http://api.wunderground.com/api/YOUR_KEY/conditions/q/VA/Springfield.xml”) as input
- Requests the data from Wunderground.
- Parses the XML file for pertinent weather data.
- Prints the data out to the console.
Below is a screenshot of weather data for five different places I’ve lived…
Full project file for Visual Studio can be found here: Wunderground_API_Test.