Example #1
0
        public static AccuWeatherHData[] GetParse8hours_OLD(int startHour, bool fromCache, int site, out int daysOld)
        {
            var url  = string.Format(urls[site], startHour);
            var age  = TimeSpan.FromTicks(0);
            var htm  = fromCache ? WebScraper.GetHtmlFromCacheOrWeb(url, out age) : WebScraper.GetHtmlFromWeb(url); //= Dbg.Htm;
            var pos  = 0;
            var stHr = DateTime.Today.AddHours(startHour);
            var awd  = new AccuWeatherHData[8];

            daysOld = (int)(DateTime.Today - (DateTime.Now - age).Date).TotalDays;

            _ = WebScrapeHelper.GetStringBetween(@"<th class=""first-col""><span>", "</span>", ref htm, ref pos);

            for (var hr = 0; hr < 8; hr++)
            {
                awd[hr]      = new AccuWeatherHData();
                _            = WebScrapeHelper.GetStringBetween(hr == 0 ? "<br />" : ">", @"</th>", ref htm, ref pos); //string[] hh = new string[] { "12am", "1am", "2am", "3am", "4am", "5am", "6am", "7am", "8am", "9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", "7pm", "8pm", "9pm", "10pm", "11pm", "12" };
                awd[hr].Time = stHr.AddHours(hr);                                                                      // for (int j = 0; j < hh.Length; j++) if (hh[j] == s) awd[i].Time = stHr.AddHours(j);
            }

            pos = htm.IndexOf(@"<th scope=""row"">Forecast</th>", StringComparison.Ordinal);
            if (pos < 0)
            {
                pos = htm.IndexOf(@"<th>Forecast</th>", StringComparison.Ordinal);
            }
            if (pos < 0)
            {
                return(awd);
            }

            for (var i = 0; i < 8; i++)
            {
                awd[i].IuhContainer = WebScrapeHelper.GetStringBetween(@"<td class=""", @""">", ref htm, ref pos);
                awd[i].ImgUrlHolder = WebScrapeHelper.GetStringBetween(@"<span", @"""", ref htm, ref pos);
                awd[i].Conditns     = WebScrapeHelper.GetStringBetween(@"<span>", @"</span>", ref htm, ref pos);
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].TempAsIs = getInt(ref htm, ref pos, awd, i, "&#176;");
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].TempFeel = getInt(ref htm, ref pos, awd, i, "&#176;");
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].Precipit = getInt(ref htm, ref pos, awd, i, "%");
            }
            for (var i = 0; i < 8; i++)
            {
                skipTd(ref htm, ref pos);
                var s = WebScrapeHelper.GetStringBetween(@">", "<", ref htm, ref pos);

                getWind(awd, i, s);
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].Humidity = getInt(ref htm, ref pos, awd, i, "%");
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].UV_Index = awd[i].Humidity = getInt(ref htm, ref pos, awd, i, "<");
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].CloudCvr = getInt(ref htm, ref pos, awd, i, "%");
            }
            for (var i = 0; i < 8; i++)
            {
                awd[i].DewPoint = getInt(ref htm, ref pos, awd, i, "&#176;");
            }

            //for (int i = 0; i < 8; i++) Console.WriteLine(awd[i]);			//Debug.Write(htm);

            return(awd);
        }
Example #2
0
        public static AccuWeatherHData[] GetParse8hours(int startHour, bool fromCache, int site, out int daysOld)
        {
            #region 2016 Sep:

            /*<div class="hourly-table overview-hourly">
             * <table>
             * <thead>
             *    <tr>
             *        <th>
             *            Thursday
             *
             *        </th>
             *            <td class="day first-col">
             *                <div>11am</div>
             *                <div class="icon-weather icon i-7-s"></div>
             *            </td>
             *            <td class="day ">
             *                <div>12pm</div>
             *                <div class="icon-weather icon i-7-s"></div>
             *            </td>
             *            <td class="day ">
             *                <div>1pm</div>
             *                <div class="icon-weather icon i-15-s"></div>
             *            </td>
             *            <td class="day ">
             *                <div>2pm</div>
             *                <div class="icon-weather icon i-15-s"></div>
             *            </td>
             *            <td class="day ">
             *                <div>3pm</div>
             *                <div class="icon-weather icon i-7-s"></div>
             *            </td>
             *            <td class="day ">
             *                <div>4pm</div>
             *                <div class="icon-weather icon i-7-s"></div>
             *            </td>
             *            <td class="day ">
             *                <div>5pm</div>
             *                <div class="icon-weather icon i-7-s"></div>
             *            </td>
             *            <td class="day last-col">
             *                <div>6pm</div>
             *                <div class="icon-weather icon i-7-s"></div>
             *            </td>
             *    </tr>
             * </thead>
             * <tbody>
             *    <tr>
             *        <th>Forecast</th>
             *            <td class="day  first-col">
             *                <span>Cloudy</span>
             *            </td>
             *            <td class="day ">
             *                <span>Cloudy</span>
             *            </td>
             *            <td class="day ">
             *                <span>T-storms</span>
             *            </td>
             *            <td class="day ">
             *                <span>T-storms</span>
             *            </td>
             *            <td class="day ">
             *                <span>Cloudy</span>
             *            </td>
             *            <td class="day ">
             *                <span>Cloudy</span>
             *            </td>
             *            <td class="day ">
             *                <span>Cloudy</span>
             *            </td>
             *            <td class="day  last-col">
             *                <span>Cloudy</span>
             *            </td>
             *    </tr>
             *    <tr>
             *        <th>Temp(°F)</th>
             *            <td class="day first-col">
             *                <span>80°</span>
             *            </td>
             *            <td class="day ">
             *                <span>80°</span>
             *            </td>
             *            <td class="day ">
             *                <span>80°</span>
             *            </td>
             *            <td class="day ">
             *                <span>81°</span>
             *            </td>
             *            <td class="day ">
             *                <span>83°</span>
             *            </td>
             *            <td class="day ">
             *                <span>83°</span>
             *            </td>
             *            <td class="day ">
             *                <span>83°</span>
             *            </td>
             *            <td class="day last-col">
             *                <span>82°</span>
             *            </td>
             *    </tr>
             *    <tr>
             *        <th>RealFeel®</th>
             *            <td class="day first-col">
             *                <span>86°</span>
             *            </td>
             *            <td class="day ">
             *                <span>85°</span>
             *            </td>
             *            <td class="day ">
             *                <span>82°</span>
             *            </td>
             *            <td class="day ">
             *                <span>82°</span>
             *            </td>
             *            <td class="day ">
             *                <span>86°</span>
             *            </td>
             *            <td class="day ">
             *                <span>85°</span>
             *            </td>
             *            <td class="day ">
             *                <span>84°</span>
             *            </td>
             *            <td class="day last-col">
             *                <span>82°</span>
             *            </td>
             *    </tr>
             *    <tr>
             *        <th>Wind(mph)</th>
             *            <td class="day first-col">
             *                <span>9 SW</span>
             *            </td>
             *            <td class="day ">
             *                <span>9 SW</span>
             *            </td>
             *            <td class="day ">
             *                <span>9 WSW</span>
             *            </td>
             *            <td class="day ">
             *                <span>10 W</span>
             *            </td>
             *            <td class="day ">
             *                <span>11 W</span>
             *            </td>
             *            <td class="day ">
             *                <span>12 W</span>
             *            </td>
             *            <td class="day ">
             *                <span>12 WSW</span>
             *            </td>
             *            <td class="day last-col">
             *                <span>11 W</span>
             *            </td>
             *    </tr>
             *
             * </tbody>
             * </table>
             * </div>
             */
            #endregion
            var url  = string.Format(urls[site], startHour);
            var age  = TimeSpan.FromTicks(0);
            var htm  = fromCache ? WebScraper.GetHtmlFromCacheOrWeb(url, out age) : WebScraper.GetHtmlFromWeb(url); //= Dbg.Htm;
            var stHr = DateTime.Today.AddHours(startHour);
            var awd  = new AccuWeatherHData[8];

            daysOld = (int)(DateTime.Today - (DateTime.Now - age).Date).TotalDays;

            for (var hr = 0; hr < 8; hr++)
            {
                awd[hr] = new AccuWeatherHData
                {
                    Time = stHr.AddHours(hr)
                };
            }

            try
            {
                agilityExplorerOne(awd, htm, "//table/thead/tr/td", doIconActn, 3);
                agilityExplorerAry(awd, htm, "//table/tbody", doRest); // the same as "//tbody"
                                                                       //agilityExplorer(htm, "//table/thead/tr");
                                                                       //agilityExplorer(htm, "//table/thead/div");
                                                                       //agilityExplorer(htm, "//table/thead/tr/div");
                                                                       //agilityExplorer(htm, "//table/thead");
                                                                       //agilityExplorer(htm, "//thead");
                                                                       //agilityExplorer(htm, "//table/tbody/tr", doExploreActn);
                                                                       //agilityExplorer(htm, "//table", doExploreActn);
            }
            catch (Exception ex) { Debug.WriteLine(ex.Message, ">>> " + System.Reflection.MethodInfo.GetCurrentMethod()?.DeclaringType.Name + "." + System.Reflection.MethodInfo.GetCurrentMethod()?.Name); }

            return(awd);
        }