public static List <WeatherDataFromAPI> GetWeatherForcast() { string key = APIKeys.WeatherAPI; string cityCode = "4994358"; // Grand Rapids string URL = $"http://api.openweathermap.org/data/2.5/forecast?id={cityCode}&APPID={key}"; JToken jt = ParseAPI.APICall(URL); // Forecast readings are every 3h: 0=now, 8=1 day, 24=3days, 39=5days minus 3h List <int> indexes = new List <int>() { 0, 8, 24, 39 }; List <WeatherDataFromAPI> weatherForecast = new List <WeatherDataFromAPI>(); foreach (int index in indexes) { WeatherDataFromAPI wd = new WeatherDataFromAPI(jt, index); wd.TemperatureC = wd.TemperatureK - 273.15; wd.TemperatureF = (wd.TemperatureC) * 9 / 5 + 32; weatherForecast.Add(wd); } return(weatherForecast); }
// GET: Weather public static List <WeatherDataFromAPI> WeatherData() { //bringing in windspeed, temperature JTokens etc. from the API JToken weather = WeatherAPIDAL.Json(); // Forecast (with an 'e') readings are every 3h: 8=1 day, 24=3days, 39=5days minus 3h List <int> indexes = new List <int>() { 0, 8, 24, 39 }; List <WeatherDataFromAPI> weatherTime = new List <WeatherDataFromAPI>(); //converting temperature from Kelvin to Celsius and Fahrenheit foreach (int index in indexes) { WeatherDataFromAPI wd = new WeatherDataFromAPI(weather, index); wd.TemperatureC = wd.TemperatureK - 273.15; wd.TemperatureF = (wd.TemperatureC) * 9 / 5 + 32; weatherTime.Add(wd); } return(weatherTime); }