Exemplo n.º 1
0
        public void get_forecast(Dictionary <WeatherPeriod, WeatherInfo> weather)
        {
            string forecast = _sitereader.forecast();

            if (forecast == null)
            {
                throw new Exception("incorrect current weather structure ");
            }

            XmlDocument pg = new XmlDocument();

            pg.LoadXml(forecast);

            XmlNode pgd_forecast = pg.DocumentElement;
            var     day_divs     = pgd_forecast.SelectNodes("//div[@class = 'card']");

            if (day_divs.Count == 0)
            {
                day_divs = pgd_forecast.SelectNodes("//article[@class = 'card']");
            }

            int day_period = 0;

            for (int day = 0; day < day_divs.Count; day++)
            {
                XmlNode day_div = day_divs[day];

                var table_rows = day_div.SelectNodes("./dd[@class='forecast-details__day-info']/table[@class = 'weather-table']/tbody[@class = 'weather-table__body']/tr[@class = 'weather-table__row']");
                if (table_rows.Count == 0)
                {
                    table_rows = day_div.SelectNodes("./div[@class='forecast-details__day-info']/table[@class = 'weather-table']/tbody[@class = 'weather-table__body']/tr[@class = 'weather-table__row']");
                }

                for (int period = 0; period < 4; period++) // утро, день, вечер, ночь
                {
                    XmlNode     row = table_rows[period];
                    WeatherInfo w   = new WeatherInfo();

                    get_daypart_weather(row, w);
                    if (day_period < day_periods.Length)
                    {
                        weather[day_periods[day_period]] = w;
                    }

                    day_period++;
                }
            }
        }
Exemplo n.º 2
0
        private void read_ngs_forecast()
        {
            bool success = true;

            _succeeded = true;

            try
            {
                string forecast = _sitereader.forecast();
                if (forecast == null)
                {
                    throw new Exception("NGS forecast: can't find 3 day forecast table");
                }

                XmlDocument pg = new XmlDocument();
                pg.LoadXml(forecast);

                XmlNode pgd_detailed = pg.DocumentElement;
                extract_3days_forecast(pgd_detailed);
            }
            catch (Exception e)
            {
                success      = false;
                _error_descr = e.Message;

                string fname = string.Format("{0} -- {1}", DateTime.Now.ToString("yyyy_MM_dd HH-mm-ss"), _error_descr);
                //File.WriteAllText(fname, browser_.Html);
            }

            finally
            {
                if (!success)
                {
                    lock (_locker)
                    {
                        _succeeded = false;
                    }
                }
            }

            try
            {
                _sitereader.getrest();
            }
            catch (Exception e)
            {
            }
        }