Exemple #1
0
        public static List <Forcast> OpenWeatherGetForcast(string Location)
        {
            LatLng          l        = GetLatLng(Location);
            HttpWebRequest  request  = WebRequest.CreateHttp($"http://api.openweathermap.org/data/2.5/forecast?lat={l.Lat}&lon={l.Lng}&units=imperial&APPID={Secret.OpenKey}");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    rd       = new StreamReader(response.GetResponseStream());
            string          APItext  = rd.ReadToEnd();
            JToken          t        = JToken.Parse(APItext);

            List <Forcast> fullList = new List <Forcast>();
            List <JToken>  x        = t["list"].ToList();

            foreach (JToken token in x)
            {
                Forcast y = new Forcast(token);
                fullList.Add(y);
            }
            List <Forcast> fiveDays = new List <Forcast>();

            fiveDays.Add(fullList[0]);
            fiveDays.Add(fullList[7]);
            fiveDays.Add(fullList[15]);
            fiveDays.Add(fullList[23]);
            fiveDays.Add(fullList[31]);
            return(fiveDays);
        }
Exemple #2
0
        public static Forcast OpenWeatherCurrentForcast(string Location)
        {
            LatLng          l        = GetLatLng(Location);
            HttpWebRequest  request  = WebRequest.CreateHttp($"http://api.openweathermap.org/data/2.5/weather?lat={l.Lat}&lon={l.Lng}&units=imperial&APPID={Secret.OpenKey}");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    rd       = new StreamReader(response.GetResponseStream());
            string          APItext  = rd.ReadToEnd();
            JToken          t        = JToken.Parse(APItext);
            Forcast         f        = new Forcast(t);

            return(f);
        }