Exemple #1
0
        public static List<Weather> GetForecast()
        {
            ClientSettings.ApiUrl = "http://api.openweathermap.org/data/2.5";
            ClientSettings.ApiKey = "b4cfe852134c38f5a1bfb50559954bbf";

            List<Weather> result = new List<Weather>();

            var request = WeatherNet
                .Clients
                .SixteenDaysForecast
                .GetByCityId(CITY_ID, 7, "es", "metric");

            if (!request.Success)
            {
                result.Add(new Weather());
                return result;
            }

            var forecast = request.Items;
            DateTime now = DateTime.Now;
            DateTime tomorrow = now.AddDays(1);
            //var dayForecast = forecast.Where(i => i.Date.ToUniversalTime().Day.Equals(now.ToUniversalTime().Day));

            foreach (WeatherNet.Model.SixteenDaysForecastResult item in forecast)
            {
                if (!item.Date.Day.Equals(now.Day))
                {
                    Weather weather = new Weather();
                    weather.temperature = Math.Round(item.Temp, 0).ToString();
                    weather.icon = GetIcon(item.Icon);
                    weather.dayOfWeek =
                        item.Date.Day
                        .Equals(tomorrow.Day) ? "mañana" : LocaleDayOfWeek(item.Date.DayOfWeek);

                    result.Add(weather);
                }
            }

            return result;
        }
Exemple #2
0
        //public static Weather Today;
        /*private static List<string> ComposeForecast()
        {
            ClientSettings.ApiUrl = "http://api.openweathermap.org/data/2.5";
            ClientSettings.ApiKey = "b4cfe852134c38f5a1bfb50559954bbf";

            List<string> result = new List<string>();
            var forecast = GetForecast();
            forecast.Insert(0, GetWeather());

            foreach (Weather item in forecast)
            {
                if (item.dayOfWeek.Equals("Hoy"))
                {
                    ComposeWeatherToday(item.temperature, )
                    continue;
                }
                Weather weather = new Weather();
                weather.temperature = Math.Round(item.Temp, 0).ToString();
                weather.icon = GetIcon(item.Icon);
                weather.dayOfWeek = LocaleDayOfWeek(item.Date.DayOfWeek);

                result.Add(weather);
            }

        }*/
        public static Weather GetWeather()
        {
            ClientSettings.ApiUrl = "http://api.openweathermap.org/data/2.5";
            ClientSettings.ApiKey = "b4cfe852134c38f5a1bfb50559954bbf";

            Weather todayWeather = new Weather();

            var request = WeatherNet
                .Clients
                .CurrentWeather
                .GetByCityId(CITY_ID, "es", "metric");

            if (!request.Success)
            {
                return (todayWeather);
            }

            var weather = request.Item;

            todayWeather.icon = GetIcon(weather.Icon);
            todayWeather.dayOfWeek = "Hoy"; //huehuehue
            todayWeather.temperature = Math.Round(weather.Temp, 0).ToString();

            return todayWeather;
        }