Ejemplo n.º 1
0
        private List <string> WeatherToday(string location)
        {
            List <string> output;
            Coordinates   coordinates;

            try
            {
                coordinates = _lookup.Lookup(location);
            }
            catch (Exception e)
            {
                Console.WriteLine("Location Lookup failure: " + e.Message);
                if (e.InnerException != null && !string.IsNullOrWhiteSpace(e.InnerException.Message))
                {
                    Console.WriteLine("--> " + e.InnerException.Message);
                }

                return(new List <string> {
                    "Could not find " + location
                });
            }

            var         weatherRequest = new WeatherLookup(_apiKeys.ForecastIoKey, coordinates.Latitude, coordinates.Longitude);
            WeatherData weather;

            weather = weatherRequest.Get();

            try
            {
            }
            catch (Exception e)
            {
                Console.WriteLine("Weather Lookup failure: " + e.Message);
                if (e.InnerException != null && !string.IsNullOrWhiteSpace(e.InnerException.Message))
                {
                    Console.WriteLine("--> " + e.InnerException.Message);
                }

                return(new List <string> {
                    "Found " + coordinates.Name + " but could not find any weather there."
                });
            }

            var wToday = weather.currently;

            output = new List <string> {
                string.Format("Weather for {0}: {1} and {2}, {3}% Humidity and {4} Winds.",
                              coordinates.Name, Temp(wToday.temperature), wToday.summary, wToday.humidity * 100, Windspeed(wToday.windSpeed))
            };

            return(output);
        }
Ejemplo n.º 2
0
        private List <string> WeatherForecast(string location)
        {
            List <string> output = new List <string>();
            Coordinates   coordinates;

            try
            {
                coordinates = _lookup.Lookup(location);
            }
            catch
            {
                return(new List <string> {
                    "Could not find " + location
                });
            }

            var         weatherRequest = new WeatherLookup(_apiKeys.ForecastIoKey, coordinates.Latitude, coordinates.Longitude);
            WeatherData weather;

            try
            {
                weather = weatherRequest.Get();
            }
            catch
            {
                return(new List <string> {
                    "Found " + coordinates.Name + " but could not find any weather there."
                });
            }


            output.Add("3 day forecast for: " + coordinates.Name);

            var dailyWeather = weather.daily.data.Skip(2).Take(3);

            foreach (var dayWeather in dailyWeather)
            {
                output.Add(string.Format("{0}: {1} {2} to {3}",
                                         TimeFromEpoch(dayWeather.time).DayOfWeek,
                                         dayWeather.summary,
                                         Temp(dayWeather.temperatureMin),
                                         Temp(dayWeather.temperatureMax)));
            }

            return(output);
        }