World Weather Online

World weather online does not provide free api keys anymore. It was my favorite weather service every time I needed to work with weather data. Fortunately my old API key still works and I decided to add weather details to my diary. First, I have created C# classes from JSON online, then thanks to awesome Newtonsoft.Json parser it's easy to work with API results. I request and store weather data every hour. This way I know how was the weather each hour every day. I launched the script at midday, hence missing data from the morning.

Classespublic class WorldWeatherOnline
{
    public Data data { get; set; }

    public class Request
    {
        public string type { get; set; }
        public string query { get; set; }
    }

    public class WeatherIconUrl
    {
        public string value { get; set; }
    }

    public class WeatherDesc
    {
        public string value { get; set; }
    }

    public class CurrentCondition
    {
        public string observation_time { get; set; }
        public string temp_C { get; set; }
        public string temp_F { get; set; }
        public string weatherCode { get; set; }
        public IList<WeatherIconUrl> weatherIconUrl { get; set; }
        public IList<WeatherDesc> weatherDesc { get; set; }
        public string windspeedMiles { get; set; }
        public string windspeedKmph { get; set; }
        public string winddirDegree { get; set; }
        public string winddir16Point { get; set; }
        public string precipMM { get; set; }
        public string humidity { get; set; }
        public string visibility { get; set; }
        public string pressure { get; set; }
        public string cloudcover { get; set; }
    }

    public class Weather
    {
        public string date { get; set; }
        public string tempMaxC { get; set; }
        public string tempMaxF { get; set; }
        public string tempMinC { get; set; }
        public string tempMinF { get; set; }
        public string windspeedMiles { get; set; }
        public string windspeedKmph { get; set; }
        public string winddirection { get; set; }
        public string winddir16Point { get; set; }
        public string winddirDegree { get; set; }
        public string weatherCode { get; set; }
        public IList<WeatherIconUrl> weatherIconUrl { get; set; }
        public IList<WeatherDesc> weatherDesc { get; set; }
        public string precipMM { get; set; }
    }

    public class Data
    {
        public IList<Request> request { get; set; }
        public IList<CurrentCondition> current_condition { get; set; }
        public IList<Weather> weather { get; set; }
    }
}
Calling APIWorldWeatherOnline wwo = new WorldWeatherOnline();

using (WebClient wc = new WebClient())
{
    string json = wc.DownloadString("http://api.worldweatheronline.com/free/v1/weather.ashx?key={WWO_API_KEY}&q={QUERY_LOCATION}&format=json");

    wwo = JsonConvert.DeserializeObject<WorldWeatherOnline>(json);
}


Back