예제 #1
0
        public string WeaImageUr_ => $"http://vortex.accuweather.com/adc2010/images/slate/icons/{ImgUrlHolder}.svg"; // public string WeaImageUrl { get { return IuhContainer == null ? "" : string.Format(urf, (ImgUrlHolder.Split('-')[1].Length < 2 ? "0" : "") + ImgUrlHolder.Split('-')[1]); } }

        public static List <HourWeatherData> GetHourForecast(int max96, bool fromCache, int site = 0)
        {
            //max96 = 144; // <== Mar2016. 96; //jun2013: ignore less than max - take max/everything should not be too much longer than just a part.
            var l = new List <HourWeatherData>();

            for (var startHour = DateTime.Now.Hour > 8 ? 8 : DateTime.Now.Hour; startHour < max96; startHour += 8)
            {
                var awd8hr = AccuWeatherHData.GetParse8hours(startHour, fromCache, site, out var daysOld);
                for (var hr = 0; hr < awd8hr.Length; hr++)
                {
                    l.Add(new HourWeatherData {
                        Time = awd8hr[hr].Time.AddDays(-daysOld), ConditionsDescription = awd8hr[hr].Conditns, ConditionsImageUrl = awd8hr[hr].WeaImageUrl, Temp = awd8hr[hr].TempAsIs, TempFeel = awd8hr[hr].TempFeel
                    });
                }
            }

            return(l);
        }
예제 #2
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);
        }
예제 #3
0
        static void doIconActn(AccuWeatherHData awd, HtmlNode tr, int max)
        {
            //77 Debug.Write(tr.ChildNodes.Count() > max ? $"   x[1]:{(tr.ChildNodes[1]).InnerHtml} : x[{max}]:{(tr.ChildNodes[max]).OuterHtml} " : $"  --------------- {tr.ChildNodes.Count()} < {max} --------------- ");

            var ss = tr.ChildNodes[max].OuterHtml[30..].Split(new[] { '-', '"' });
예제 #4
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);
        }