public async Task <ForecastGeneralized> GetData(string uniqueCityId, string cityName) { using WebClient client = new WebClient(); string doc = client.DownloadString(Uri.EscapeUriString(string.Format("https://www.bbc.com/weather/{0}?day=1/application/json", uniqueCityId))); doc = doc.Substring(doc.IndexOf("application/json")); doc = doc.Substring(doc.IndexOf("{")); doc = doc.Substring(0, doc.IndexOf("<")); BBCScrapRootObject weatherinfo = JsonConvert.DeserializeObject <BBCScrapRootObject>(doc); ForecastGeneralized forecastGeneralized = new ForecastGeneralized { Name = weatherinfo.data.location.name.ToLower(), Provider = "BBC", CreationDate = DateTime.Now, Forecasts = new List <ForecastsG>() }; foreach (var day in weatherinfo.data.forecasts.Take(7)) { foreach (var forecast in day.detailed.reports) { ForecastsG item = new ForecastsG { ForecastTime = Convert.ToDateTime(Convert.ToString(forecast.localDate + "T" + forecast.timeslot)), temperature = forecast.temperatureC }; forecastGeneralized.Forecasts.Add(item); } } return(await Task.FromResult(forecastGeneralized)); }
public async Task <ForecastGeneralized> GetData(string uniqueCityId, string cityName) { OWMOneCallRootObject weatherinfo = await Deserialize <OWMOneCallRootObject>("OWM", string.Format("onecall?{0}&units=metric&appid=4bd458b0d9e2bfadbed92b6b73ce4274", uniqueCityId)); ForecastGeneralized forecastGeneralized = new ForecastGeneralized { Name = cityName, CreationDate = DateTime.Now, Provider = "OWM", Forecasts = new List <ForecastsG>() }; foreach (var forecast in weatherinfo.hourly) { ForecastsG item = new ForecastsG { temperature = forecast.temp, ForecastTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromSeconds(forecast.dt), }; item.ForecastTime = Convert.ToDateTime(item.ForecastTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss")); forecastGeneralized.Forecasts.Add(item); } return(forecastGeneralized); }
public async Task <ForecastGeneralized> GetData(string uniqueCityId, string cityName) { MeteoRootObject weatherinfo = await Deserialize <MeteoRootObject>("METEO", string.Format("places/{0}/forecasts/long-term", uniqueCityId)); ForecastGeneralized forecastGeneralized = new ForecastGeneralized { Name = weatherinfo.place.name.ToLower(), Provider = "Meteo", CreationDate = DateTime.Now, Forecasts = new List <ForecastsG>() }; foreach (var forecast in weatherinfo.forecastTimestamps) { ForecastsG item = new ForecastsG { ForecastTime = forecast.forecastTimeUtc, temperature = forecast.airTemperature }; forecastGeneralized.Forecasts.Add(item); } return(forecastGeneralized); }