}// end of method CompassDirection public static bool DeserializeYahooJSON(string strJSON, ref YahooWeatherDataItem yahooWeatherData) { yahooWeatherData = JsonConvert.DeserializeObject <YahooWeatherDataItem>(strJSON); if (yahooWeatherData == null) { return(false); }// end of if block else { return(true); } // end of else block } // end of method DeserializeJSON
} // end of method DeserializeJSON public static void LoadYahooWeatherData(YahooWeatherDataItem wxData) { string city = $"{wxData.query.results.channel.location.city}, {wxData.query.results.channel.location.region}"; string country = wxData.query.results.channel.location.country; string datePublished = wxData.query.results.channel.item.pubDate; string currentTemperature = wxData.query.results.channel.item.condition.temp + "\u00B0" + wxData.query.results.channel.units.temperature; string currentWXCondition = (!wxData.query.results.channel.item.condition.code.Equals("3200") ? yahooWeatherCodes[int.Parse(wxData.query.results.channel.item.condition.code)].ToProperCase() : "N/A"); string windChill = wxData.query.results.channel.wind.chill + "\u00B0" + wxData.query.results.channel.units.temperature; string windDirection = CompassDirection(double.Parse(wxData.query.results.channel.wind.direction)); string windSpeed = wxData.query.results.channel.wind.speed; string wind = windDirection + " " + windSpeed + " " + wxData.query.results.channel.units.speed; string humidity = wxData.query.results.channel.atmosphere.humidity + "%"; string pressure = wxData.query.results.channel.atmosphere.pressure + " " + wxData.query.results.channel.units.pressure; string rising = wxData.query.results.channel.atmosphere.rising; string visibility = wxData.query.results.channel.atmosphere.visibility + " " + wxData.query.results.channel.units.distance; string sunrise = wxData.query.results.channel.astronomy.sunrise; string sunset = wxData.query.results.channel.astronomy.sunset; // Header Console.WriteLine($"Current weather data for the city of {city} in {country}"); Console.WriteLine(); // Weather Conditions Console.WriteLine("\t*** Current Weather Conditions ***"); Console.WriteLine("\t\tDate Published: " + datePublished); Console.WriteLine("\t\tCurrent Temperature: " + currentTemperature); Console.WriteLine("\t\tCurrent Conditions: " + currentWXCondition); Console.WriteLine(); // Wind Readings Console.WriteLine("\t*** Wind ***"); Console.WriteLine("\t\tWind Chill: " + windChill); Console.WriteLine("\t\tWind: " + wind); Console.WriteLine(); // Atmospheric Readings Console.WriteLine("\t*** Atmosphere ***"); Console.WriteLine("\t\tHumidity: " + humidity); Console.WriteLine("\t\tPressure: " + pressure); Console.WriteLine("\t\tRising: " + rising); Console.WriteLine("\t\tVisibility: " + visibility); Console.WriteLine(); // Astronomy Console.WriteLine("\t*** Astronomy ***"); Console.WriteLine("\t\tSunrise: " + sunrise); Console.WriteLine("\t\tSunset: " + sunset); Console.WriteLine(); Console.WriteLine(); // Five Day Forcast Console.WriteLine("\t*** Five Day Forecast ***"); Console.WriteLine(); int i = 1; // loop throught hte forcast data. only 5 days are needed foreach (var wxForecast in wxData.query.results.channel.item.forecast) { string fCondition = !wxData.query.results.channel.item.condition.code.Equals("3200") ? yahooWeatherCodes[int.Parse(wxForecast.code)].ToProperCase() : "N/A"; string fDay = wxForecast.day; string fDate = (DateTime.Parse(wxForecast.date) == DateTime.Today ? string.Format("{0:MMMM d, yyyy}", DateTime.Parse(wxForecast.date)) + " (Today)" : string.Format("{0:MMMM d, yyyy}", DateTime.Parse(wxForecast.date))); string fHigh = wxForecast.high + "\u00B0" + wxData.query.results.channel.units.temperature; string fLow = wxForecast.low + "\u00B0" + wxData.query.results.channel.units.temperature; //Console.WriteLine( "\t\tCode: " + wxForecast.code ); Console.WriteLine("\t\tDay: " + fDay); Console.WriteLine("\t\tDate: " + fDate); Console.WriteLine("\t\tHigh: " + fHigh); Console.WriteLine("\t\tLow: " + fLow); Console.WriteLine("\t\tCondition: " + fCondition); //Console.WriteLine( "\t\tText: " + wxForecast.text ); // Yahoo provides this data but others may not Console.WriteLine(); if (i == 5) { break; }// end of if block i++; // increment sentinel }// end of for each loop Console.WriteLine(); } // end of method LoadYahooWeatherData