示例#1
0
        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));
        }
示例#2
0
        void DbUpdateActual(ForecastGeneralized generalized, string cityId, WeatherContext _context)
        {
            var objectFromDatabase = _context.Cities
                                     .Include(i => i.ActualTemparture)
                                     .First(i => i.Name == cityId);

            objectFromDatabase.ActualTemparture.Add(new ActualTemperature
            {
                ForecastTime = generalized.Forecasts.First().ForecastTime,
                Temperature  = generalized.Forecasts.First().temperature
            });
            _context.SaveChanges();
        }
示例#3
0
        void DBUpdateForecasts(ForecastGeneralized forecastGeneralized, string CityId, WeatherContext _context)
        {
            var objectFromDatabase = _context.Cities
                                     .Include(city => city.Forecasts)
                                     .First(city => city.Name == CityId);

            foreach (var forecast in forecastGeneralized.Forecasts)
            {
                objectFromDatabase.Forecasts.Add(new Forecasts
                {
                    CreatedDate  = forecastGeneralized.CreationDate,
                    ForecastTime = forecast.ForecastTime,
                    Temperature  = forecast.temperature,
                    Provider     = forecastGeneralized.Provider,
                });
            }
            _context.SaveChanges();
        }
示例#4
0
        public async Task <ForecastGeneralized> GetData(string uniqueCityId, string cityName)
        {
            OWMNowRootObject weatherinfo = await Deserialize <OWMNowRootObject>("OWM", string.Format("weather?{0}&units=metric&appid=4bd458b0d9e2bfadbed92b6b73ce4274", uniqueCityId));

            ForecastGeneralized forecastGeneralized = new ForecastGeneralized
            {
                CreationDate = DateTime.Now,
                Name         = weatherinfo.name,
                Provider     = "OWM",
                Forecasts    = new List <ForecastsG>
                {
                    new ForecastsG
                    {
                        ForecastTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromSeconds(weatherinfo.dt),
                        temperature  = weatherinfo.main.temp
                    }
                }
            };

            return(forecastGeneralized);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }