예제 #1
0
        public List <WeatherObservation> WeatherData(string location, DateTime date)
        {
            string result;

            using (WebClient cc = new WebClient())
            {
                var url = string.Format(FeedURL, date.Year, date.Month, date.Day);
                result = cc.DownloadString(url);
            }

            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(result);

            var observations = htmlDoc.DocumentNode.SelectNodes("//table[@id='obsTable']/tbody/tr");

            var obs = observations.Select((x, i) =>
            {
                var time = x.ChildNodes[1].InnerText.TryCastToTime();
                var wo   = new WeatherObservation()
                {
                    //TODO: fix, some of the parsing is WRONG, check files...
                    //there's an error with the days too! YEAH...
                    DateTime    = date.Add(time),
                    Temperature = GetDoubleFromTD(x.ChildNodes[3]),
                    DewPoint    = GetDoubleFromTD(x.ChildNodes[7]),
                    Humidity    = x.ChildNodes[9].InnerText.Replace("%", "").TryCastToDouble(),
                    Pressure    = GetDoubleFromTD(x.ChildNodes[11]),
                    WindDir     = x.ChildNodes[15].InnerText,
                    WindSpeed   = GetDoubleFromTD(x.ChildNodes[17])
                };
                return(wo);
            }).ToList();

            return(obs);
        }
예제 #2
0
파일: Downloader.cs 프로젝트: af3290/ema
        public List<WeatherObservation> WeatherData(string location, DateTime date)
        {
            string result;

            using (WebClient cc = new WebClient())
            {
                var url = string.Format(FeedURL, date.Year, date.Month, date.Day);
                result = cc.DownloadString(url);
            }

            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(result);

            var observations = htmlDoc.DocumentNode.SelectNodes("//table[@id='obsTable']/tbody/tr");

            var obs = observations.Select((x, i) =>
            {
                var time = x.ChildNodes[1].InnerText.TryCastToTime();
                var wo = new WeatherObservation()
                {
                    //TODO: fix, some of the parsing is WRONG, check files...
                    //there's an error with the days too! YEAH...
                    DateTime = date.Add(time),
                    Temperature = GetDoubleFromTD(x.ChildNodes[3]),
                    DewPoint = GetDoubleFromTD(x.ChildNodes[7]),
                    Humidity = x.ChildNodes[9].InnerText.Replace("%", "").TryCastToDouble(),
                    Pressure = GetDoubleFromTD(x.ChildNodes[11]),
                    WindDir = x.ChildNodes[15].InnerText,
                    WindSpeed = GetDoubleFromTD(x.ChildNodes[17])
                };
                return wo;
            }).ToList();

            return obs;
        }