public static async Task <Weather> GetWeather(string city)
        {
            string key         = "5284fcb324d66054643af9c58136714f";
            string queryString = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=metric&appid=" + key;

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            Weather weather = new Weather();


            if (results != null)
            {
                weather.Title       = results["name"];
                weather.Tempurature = results["main"]["temp"];
                weather.Humidity    = results["main"]["humidity"];
                weather.Wind        = results["wind"]["speed"];
                weather.description = results["weather"][0]["description"];


                weather.Sunrize = ConvertFromUnixTimestamp((double)results["sys"]["sunrise"]).ToString("HH:mm");
                weather.Sunset  = ConvertFromUnixTimestamp((double)results["sys"]["sunset"]).ToString("HH:mm");

                return(weather);
            }

            return(weather);
        }
Beispiel #2
0
        public static async Task <Weather> GetWeatherByCity(string city)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "e7de5f21f7e48a34cabd482680b17a73";
            string queryStringByCity = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + key;

            var results = await DataService.getDataFromService(queryStringByCity).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];

                //string s = (string)results["main"]["temp"];
                //weather.Temperature = ConvertFahrenheitToCelsius(Convert.ToDouble(s)).ToString() + " C";
                weather.Temperature = (string)results["main"]["temp"] + " F";

                weather.Wind       = (string)results["wind"]["speed"] + " mph";
                weather.Humidity   = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "42c0e77ad3018dc3c35da3da97274faf";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + "&appid=" + key;

            //02116
            try {
                var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

                Weather weather = new Weather {
                    Title       = (string)results["name"],
                    Temperature = (string)results["main"]["temp"] + " F",
                    Wind        = (string)results["wind"]["speed"] + " mph",
                    Humidity    = (string)results["main"]["humidity"] + " %",
                    Visibility  = (string)results["weather"][0]["main"]
                };
                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            catch (Exception ex) {
            }
            return(new Weather()
            {
                Title = "Postal Code not found"
            });
        }
Beispiel #4
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            string key         = "c4af70b3395e852a0b0db76915f1813a";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",es&appid=" + key + "&units=metric";

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " ºC";
                weather.Wind        = (string)results["wind"]["speed"] + " Km/h";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
        public static async Task <Weather> GetWeather(string zipCode)
        {
            string apiKey      = "d0717209fc7a503ecc78f94f28bd089f";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + apiKey + "&units=imperial";

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        public static async Task <Weather> GetWeather(string cityName)
        {
            string key         = "088bf18e1e0dff6e36e16733f079d626";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?q="
                                 + cityName + "&units=metric&appid=" + key;

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                //double F = (double)results["main"]["temp"];
                //double C = (F - 32) / 1.8;
                //string Temp = System.Convert.ToString(C);
                weather.Temperature = (string)results["main"]["temp"] + " C";
                double mph     = (double)results["wind"]["speed"];
                double km      = mph * 1.609344;
                string convert = System.Convert.ToString(km);
                weather.Wind       = (string)convert + " km";
                weather.Humidity   = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "YOUR API KEY HERE";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?q="
                                 + zipCode + "&units=metric&appid=" + key;

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false); // GET-datakald - se DataService.cs - JSON-objekt retur

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + "° C";
                weather.Wind        = (string)results["wind"]["speed"] + " m/sek";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather); // Parset og sat ind i weather-objekt
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
        public static async Task <Weather> getWeather(String zipCode)
        {
            String key   = "d74c398993402af3969df1e1e60103f1";
            String query = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + key + "&units=imperial";

            dynamic results = await DataService.getDataFromService(query).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.title       = (String)results["name"];
                weather.temperature = (String)results["main"]["temp"] + " F";
                weather.wind        = (String)results["wind"]["speed"] + " mph";
                weather.humidity    = (String)results["main"]["humidity"] + " %";
                weather.visibility  = (String)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.sunrise = sunrise.ToString() + " UTC";
                weather.sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #9
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "508fa55216d8dec95008f726d480863d";
            //units=imperial (F), metric (C°)
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",us&appid=" + key + "&units=metric";

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " C°";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
    { public static async Task <Weather> GetWeather(string zipCode)
      {
          //Sign up for a free API key at http://openweathermap.org/appid
          string key         = "55fe8f369693ae787ed6e6c0ea87a913";
          string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + key + "&units=imperial";

          if (key != "55fe8f369693ae787ed6e6c0ea87a913")
          {
              throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable.");
          }
          dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

          if (results["weather"] != null)
          {
              Weather weather = new Weather();
              weather.Title       = (string)results["name"];
              weather.Temperature = (string)results["main"]["temp"] + " F";
              weather.Wind        = (string)results["wind"]["speed"] + " mph";
              weather.Humidity    = (string)results["main"]["humidity"] + " %";
              weather.Visibility  = (string)results["weather"][0]["main"];
              DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
              DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
              DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
              weather.Sunrise = sunrise.ToString() + " UTC";
              weather.Sunset  = sunset.ToString() + " UTC";
              return(weather);
          }

          else
          {
              return(null);
          }
      }
Beispiel #11
0
        public static async Task <Weather> GetWeather(string zipCode, string units = "kelvin")
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "fc9f6c524fc093759cd28d41fda89a1b";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + "&appid=" + key + "&units=" + units;

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather
                {
                    Title       = (string)results["name"],
                    Temperature = (string)results["main"]["temp"] + " F",
                    Wind        = (string)results["wind"]["speed"] + " mph",
                    Humidity    = (string)results["main"]["humidity"] + " %",
                    Visibility  = (string)results["weather"][0]["main"]
                };

                DateTime time    = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #12
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "Insert_api_key";
            string queryString = "https://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",us&appid=" + key + "&units=imperial";

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);

                Weather weather = new Weather
                {
                    Title       = (string)results["name"],
                    Temperature = (string)results["main"]["temp"] + " F",
                    Wind        = (string)results["wind"]["speed"] + " mph",
                    Humidity    = (string)results["main"]["humidity"] + " %",
                    Visibility  = (string)results["weather"][0]["main"],
                    Sunrise     = sunrise.ToString() + " UTC",
                    Sunset      = sunset.ToString() + " UTC",
                };
                return(weather);
            }

            return(null);
        }
Beispiel #13
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "c2c1a0fd0187f7e168bce4c6d6c4a723";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + "&appid=" + key;

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];
                weather.Icon        = (string)results["weather"][0]["icon"];


                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #14
0
        public static async Task <Weather> GetWeather(string zipcode)
        {
            // Load the API Key
            string apiKey = "YOUR API KEY HERE";

            // Create the request to send to the server
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" +
                                 zipcode + ",us&appid=" + apiKey + "&units=imperial";

            // Send the request to the server
            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            // If a response was sent back, receive the data
            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";

                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #15
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            string queryString =
                "https://query.yahooapis.com/v1/public/yql?q=select+*+from+weather.forecast+where+location=" +
                zipCode + "&format=json";

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            dynamic weatherOverview = results["query"]["results"]["channel"];

            if ((string)weatherOverview["description"] != "Yahoo! Weather Error")
            {
                Weather weather = new Weather();

                weather.Title = (string)weatherOverview["description"];

                dynamic wind = weatherOverview["wind"];
                weather.Temperature = (string)wind["chill"] + " F";
                weather.Wind        = (string)wind["speed"] + " mph";

                dynamic atmosphere = weatherOverview["atmosphere"];
                weather.Humidity   = (string)atmosphere["humidity"] + " %";
                weather.Visibility = (string)atmosphere["visibility"] + " miles";

                dynamic astronomy = weatherOverview["astronomy"];
                weather.Sunrise = (string)astronomy["sunrise"];
                weather.Sunset  = (string)astronomy["sunset"];

                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #16
0
        public static async Task <Weather> GetWeather()
        {
            //Sign up for a free API key at http://openweathermap.org/appid

            string key       = "334697e46cd896224b89789b9786eb9b";
            string latitude  = "55.676098";
            string longitude = "12.5683";

            string queryString = "http://api.openweathermap.org/data/2.5/weather?lat="
                                 + latitude + "&lon=" + longitude + "&units=metric&appid=" + key;


            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #17
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string  key         = "3ecc1f2320902bc3d5202ba51d66dc62";
            string  queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + key + "&units=imperial";
            JObject results     = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];
                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                // added
                weather.HighTemp      = (string)results["main"]["temp_max"] + " F";
                weather.LowTemp       = (string)results["main"]["temp_min"] + " F";
                weather.AirPressure   = (string)results["main"]["pressure"] + " hPa";
                weather.WindDirection = (string)results["wind"]["deg"] + " Degress";

                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #18
0
        public async Task <Weather> GetWeather()
        {
            //Currently we are always using Copenhagen as reference. In a real live scenario, we would use dependency injection to inject the native GPS service into
            //this class in order to get the proper latitude and longitude

            //Sign up for a free API key at http://openweathermap.org/appid
            string key       = "334697e46cd896224b89789b9786eb9b";
            string latitude  = "55.676098";
            string longitude = "12.5683";

            string queryString = "http://api.openweathermap.org/data/2.5/weather?lat="
                                 + latitude + "&lon=" + longitude + "&units=metric&appid=" + key;

            var results = await dataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Place    = (string)results["name"];
                weather.Altitude = "??"; //have not yet figured out how to retrieve the altitude


                //parsing date/time
                var    timeUnixEpochString = (string)results["dt"];
                double timeUnixEpochDouble;
                var    unixEpochParsedOk = Double.TryParse(timeUnixEpochString, out timeUnixEpochDouble);
                if (unixEpochParsedOk)
                {
                    DateTime localtime = UnixTimestampToDateTime(timeUnixEpochDouble);
                    weather.DateString = localtime.ToString("dddd, MMMM d");
                    weather.TimeString = localtime.ToString("HH:mm");
                }

                weather.Humidity = (string)results["main"]["humidity"];

                weather.TemperatureCelcius = (string)results["main"]["temp"];

                //parsing winddirection
                var    windDirectionString = (string)results["wind"]["deg"];
                double windDirectionDouble;
                var    windParsedOk = Double.TryParse(windDirectionString, out windDirectionDouble);
                if (windParsedOk)
                {
                    weather.WindDirection = windDirectionDouble;
                }
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #19
0
        public async Task <Weather> GetWeather()
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "34eca85ba279224ae2ca92f34bef7c82";

            //string latitude = "55.676098";
            //string longitude = "12.5683";
            string cityID = "2618425";

            string queryString = "http://api.openweathermap.org/data/2.5/forecast?id="
                                 + cityID + "&units=metric&cnt=4&appid=" + key;

            //string queryString = "http://api.openweathermap.org/data/2.5/weather?lat="
            //    + latitude + "&lon=" + longitude + "&units=metric&appid=" + key;

            //string queryString = "http://api.openweathermap.org/data/2.5/forecast?q="
            //    + "copenhagen&units=metric&appid=" + key;

            var results = await dataService.getDataFromService(queryString).ConfigureAwait(false);

//            Debug.WriteLine(queryString);

//            if (results["weather"] != null)  // Med "weather" API skal man validere på "weather"
            if (results["city"] != null)     //   Med "forecast" API skal man validere på "city"
            {
//                Debug.WriteLine("OKOKOK");
                Weather weather = new Weather();
                weather.Place = (string)results["city"]["name"];

                if (results["list"][0]["dt"] != null)  // Viser dato, hentet i det første forecast
                {
                    DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                    DateTime dt   = time.AddSeconds((double)results["list"][0]["dt"]).ToLocalTime();
                    weather.DatoTid = dt.ToString("dddd', d.'dd MMMM yyyy", new CultureInfo("da"));
                }



                //weather.Temperature = (string)results["main"]["temp"] + " C";
                //weather.Wind = (string)results["wind"]["speed"] + " M/sek";
                //weather.Humidity = (string)results["main"]["humidity"] + " %";
                //weather.Visibility = (string)results["weather"][0]["main"];



                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #20
0
        public static async Task <Weather> GetWeather(string country, DateTime d)
        {
            string key = "5071ff4d395a43f095c144741170612";
            int    days;

            if (System.DateTime.Now.Month != d.Month)
            {
                days = 31 - Convert.ToInt32(d.Day) + Convert.ToInt32(System.DateTime.Now.Day);
            }
            else
            {
                days = Convert.ToInt32(System.DateTime.Now.Day) - Convert.ToInt32(d.Day);
            }

            String finalDay    = d.Year + "-" + d.Month + "-" + d.Day;
            string queryString = "http://api.apixu.com/v1/history.json?key="
                                 + key + "&q=" + country + "&dt=" + finalDay;

            Debug.WriteLine(queryString);

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            Debug.WriteLine(results);
            if (results["location"] != null)
            {
                Weather weather = new Weather();
                weather.Title              = (string)results["location"]["country"];
                weather.Temperature        = (string)results["forecast"]["forecastday"][0]["day"]["avgtemp_c"] + " ºC";
                weather.MinimumTemperature = (string)results["forecast"]["forecastday"][0]["day"]["maxtemp_c"] + " ºC";
                weather.MaximumTemperature = (string)results["forecast"]["forecastday"][0]["day"]["mintemp_c"] + " ºC";
                weather.Wind          = (string)results["forecast"]["forecastday"][0]["day"]["maxwind_kph"] + " kph";
                weather.Humidity      = (string)results["forecast"]["forecastday"][0]["day"]["avghumidity"] + " %";
                weather.Visibility    = (string)results["forecast"]["forecastday"][0]["day"]["avgvis_km"] + " km";
                weather.Precipitation = (string)results["forecast"]["forecastday"][0]["day"]["totalprecip_mm"] + " mm";
                weather.LastUpdated   = (string)results["forecast"]["forecastday"][0]["date"];
                weather.Sunset        = (string)results["forecast"]["forecastday"][0]["astro"]["sunset"];
                weather.Sunrise       = (string)results["forecast"]["forecastday"][0]["astro"]["sunrise"];

                foreach (var obj in results["forecast"]["forecastday"][0]["hour"])
                {
                    weather.Hours.Add((int)obj["temp_c"]);
                }

                return(weather);
            }
            else
            {
                return(null);
            }
        }
        public static async Task <ActualWeather> GetCoordinate(string latitude, string longitude)
        {
            string  key         = "c8a760683089adad086eef5d6a85e5a3";
            string  queryString = String.Format("http://api.openweathermap.org/data/2.5/forecast?lat={0}&lon={1}&units=metric&APPID={2}", latitude, longitude, key);
            dynamic results     = await DataService.getDataFromService(queryString);

            if (results.cod != 502)
            {
                try
                {
                    List <WeatherData> lstWeather = new List <WeatherData>();
                    foreach (var item in results.list)
                    {
                        WeatherData weather = new WeatherData(
                            (double)item.main.temp,
                            (double)item.main.temp_max,
                            (double)item.main.temp_min,
                            (double)item.wind.speed,
                            (double)item.wind.deg,
                            (double)item.main.pressure,
                            (double)item.main.humidity,
                            (double)item.main.sea_level,
                            (double)item.main.grnd_level,
                            (string)item.weather[0].main,
                            (string)item.weather[0].description,
                            (string)"http://openweathermap.org/img/w/" + item.weather[0].icon + ".png",
                            (DateTime)item.dt_txt);
                        lstWeather.Add(weather);
                    }

                    ActualWeather actuWeather = new ActualWeather(
                        (string)DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"),
                        (string)results.city.name,
                        (string)results.city.country,
                        (double)results.city.coord.lat,
                        (double)results.city.coord.lon,
                        lstWeather
                        );
                    return(actuWeather);
                }
                catch
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #22
0
        public static async Task <Weather> GetWeather(string cityName)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "34eca85ba279224ae2ca92f34bef7c82";

            string queryString = "http://api.openweathermap.org/data/2.5/weather?q="
                                 + cityName + "&units=metric&appid=" + key;

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Place = (string)results["name"];

                DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime dt   = time.AddSeconds((double)results["dt"]).ToLocalTime();
                weather.DatoTid = dt.ToString("dddd', d.'dd MMMM yyyy", new CultureInfo("da"));



                weather.Temperature = (string)results["main"]["temp"] + " C";
                weather.Wind        = (string)results["wind"]["speed"] + " M/sek";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                //DateTime now = DateTime.Now;
                //DateTime time = new DateTime(now.Year, now.Month, now.Day);
                //DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                //DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]).ToLocalTime();
                //DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]).ToLocalTime();
                //weather.Sunrise = sunrise.ToString() + " UTC";
                //weather.Sunset = sunset.ToString() + " UTC";
                //weather.Sunrise = sunrise.Day.ToString() + "/" + sunrise.Month.ToString() + "-" + sunrise.Year.ToString() + " " + sunrise.TimeOfDay.ToString();
                //weather.Sunset = sunset.Day.ToString() + "/" + sunset.Month.ToString() + "-" + sunset.Year.ToString() + " " + sunset.TimeOfDay.ToString();
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #23
0
        public async Task <Weather> GetWeather(string cityCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "d7ad57c25dc63896ccbdc046d132943e";
            //string latitude = "55.676098";
            //string longitude = "12.5683";



            //string queryString = "http://api.openweathermap.org/data/2.5/weather?lat="
            //     + latitude + "&lon=" + longitude + "&units=metric&appid=" + key;


            string queryString = "http://api.openweathermap.org/data/2.5/weather?q="
                                 + cityCode + "&units=metric&appid=" + key;

            var results = await dataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime dt   = time.AddSeconds((double)results["dt"]).ToLocalTime();
                weather.DatoTid     = dt.ToString("dddd', Den 'dd MMMM yyyy", new CultureInfo("da"));
                weather.Temperature = (string)results["main"]["temp"] + " C";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #24
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "23086a5fc99f8a80c01473fba678b3ed";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",us&appid=" + key + "&units=imperial";

            //Make sure developers running this sample replaced the API key
            if (key == "YOUR API KEY HERE")
            {
                throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable.");
            }

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather
                {
                    Title       = (string)results["name"],
                    Temperature = (string)results["main"]["temp"] + " F",
                    Wind        = (string)results["wind"]["speed"] + " mph",
                    Humidity    = (string)results["main"]["humidity"] + " %",
                    Visibility  = (string)results["weather"][0]["main"]
                };

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #25
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            //string key = "YOUR API KEY HERE";
            string key         = "3d8cf2e912c973578143971854dc8f52";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",jp&appid=" + key + "&units=imperial";

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                var kashi = results["main"]["temp"];
                var seshi = (5.0 / 9) * ((double)kashi - 32);

                var     meter   = (double)results["wind"]["speed"] * 0.447;
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                //weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Temperature = seshi.ToString() + " C";
                //weather.Wind = (string)results["wind"]["speed"] + " mph";
                weather.Wind       = meter.ToString() + "m/s";
                weather.Humidity   = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 9, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString();
                weather.Sunset  = sunset.ToString();
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #26
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "200384880dd803fea8141c5e73ace40b";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",&appid=" + key;

            //Make sure developers running this sample replaced the API key
            if (key == "200384880dd803fea8141c5e73ace40b")
            {
                throw new ArgumentException(message: "You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable");
            }

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #27
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "019c3229e8c9e12a88580660f8595283";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",us&appid=" + key + "&units=imperial";

            //Make sure developers running this sample replaced the API key
            if (key == "bc06723b9ee2fad1e929ceeb25671019")
            {
                throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable.");
            }

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #28
0
        public static async Task <Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key         = "2223e8cfe82f311004078e16682a5adf";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                                 + zipCode + ",br&appid=" + key + "&units=imperial";

            //Make sure developers running this sample replaced the API key
            //if (key != "2223e8cfe82f311004078e16682a5adf")
            //{
            //    throw new ArgumentException("Invalid API key.");
            //}

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title       = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind        = (string)results["wind"]["speed"] + " mph";
                weather.Humidity    = (string)results["main"]["humidity"] + " %";
                weather.Visibility  = (string)results["weather"][0]["main"];

                DateTime time    = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset  = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset  = sunset.ToString() + " UTC";
                return(weather);
            }
            else
            {
                return(null);
            }
        }
Beispiel #29
0
        public static async Task <Weather> RetrieveWeather(string pZipCode, string pCountryCode, bool pUseMetric)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "CHANGE THIS STRING";

            string queryString = default(String); //"http://api.openweathermap.org/data/2.5/weather?zip=";

            //IF pUseMetric, set the unitsString to "metric" else "imperial"
            string unitsString = (pUseMetric ? "metric" : "imperial");

            if (String.IsNullOrEmpty(pCountryCode)) //If Country is not specified, Open Weather Defaults to the US.
            {
                queryString = $"http://api.openweathermap.org/data/2.5/weather?zip={pZipCode},us&appid={key}&units={unitsString}";
            }
            else
            {
                queryString = $"http://api.openweathermap.org/data/2.5/weather?zip={pZipCode},{pCountryCode}&appid={key}&units={unitsString}";
            }

            //Make sure developer has replaced the API key
            if (key == "CHANGE THIS STRING") //DO NOT CHANGE THIS STRING.
            {
                throw new ArgumentOutOfRangeException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable.");
            }

            dynamic results = null;

            try
            {
                results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

                if (results["weather"] != null)
                {
                    DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

                    return(new Weather()
                    {
                        Title = (string)results["name"],
                        Temperature = (double)results["main"]["temp"],
                        Wind = (double)results["wind"]["speed"],
                        Humidity = (double)results["main"]["humidity"],
                        Visibility = (string)results["weather"][0]["main"],
                        Sunrise = $"{time.AddSeconds((double)results["sys"]["sunrise"]).ToString()} UTC",
                        Sunset = $"{time.AddSeconds((double)results["sys"]["sunset"]).ToString()} UTC"
                    });
                }
                else
                {
                    throw new Exception((string)results["message"]);
                }
            }
            catch (Exception ex)
            {
                if (results == null)
                {
                    throw new Exception($"Unable to retreived Weather data.  Please check your internet connection ({ex.Message})");
                }
                else
                {
                    throw new Exception(ex.Message);
                }
            }
        }