Пример #1
0
        public List <TMinus24hrData> GetTMinus24HrData()
        {
            var     html               = @"https://www.skiutah.com/snowreport";
            HtmlWeb web                = new HtmlWeb();
            var     htmlDoc            = web.Load(html);
            List <TMinus24hrData> data = new List <TMinus24hrData>();

            foreach (KeyValuePair <string, string> resort_id in SkiUtah_Resorts_Ids)
            {
                TMinus24hrData datum = new TMinus24hrData
                {
                    ResortName = resort_id.Key
                };

                //find resort node
                var resortNode = htmlDoc.GetElementbyId(resort_id.Value);

                //find timestamp node
                var      timeStampNode      = resortNode.Descendants("span").Where(d => d.Attributes["class"].Value == SkiUtah_TimeStamp).First();
                string   timeStampText      = timeStampNode.Descendants("strong").First().InnerHtml;
                string[] timeStampTextSplit = timeStampText.Split(" ");
                string[] timeStamp          = timeStampTextSplit.Reverse().Take(2).Reverse().ToArray();
                datum.UpdatedTime = DateTime.TryParse(string.Join(" ", timeStamp[0], timeStamp[1]), out DateTime timestamp1) ? timestamp1 : DateTime.UnixEpoch;

                //find 24 hour snow node
                var    snow24Node = resortNode.Descendants("div").Where(d => d.Attributes["class"].Value == SkiUtah_24hrSnow).First();
                string snow24Text = snow24Node.Descendants("span").First().InnerHtml;
                datum.Snow24hr_in = int.TryParse(snow24Text, out int temp1) ? temp1 : 0;

                //find snow depth node
                var    snowDepthNode = resortNode.Descendants("div").Where(d => d.Attributes["class"].Value == SkiUtah_SnowDepth).First();
                string snowDepthText = snowDepthNode.Descendants("span").First().InnerHtml;
                datum.SnowDepth_in = int.TryParse(snowDepthText, out int temp2) ? temp2 : 0;

                //timestamp this sample
                datum.SampledTime = DateTime.Now;

                data.Add(datum);
            }

            return(data);
        }
Пример #2
0
        public string ToHtml()
        {
            var builder = new StringBuilder();

            builder.Append("<html>");
            builder.AppendLine();
            builder.Append("<head>");
            builder.AppendLine();
            builder.Append("<style>");
            builder.AppendLine();
            builder.Append("table, th, td {");
            builder.AppendLine();
            builder.Append("border: 1px solid black;");
            builder.AppendLine();
            builder.Append("border-collapse: collapse;");
            builder.AppendLine();
            builder.Append("}");
            builder.AppendLine();
            builder.Append("</style>");
            builder.AppendLine();
            builder.Append("</head>");
            builder.AppendLine();
            builder.Append("<body>");
            builder.AppendLine();

            builder.Append("<h2>");
            builder.AppendLine();
            builder.Append(TimeStamp.ToString());
            builder.Append("</h2>");
            builder.AppendLine();

            builder.AppendLine();
            builder.AppendLine();

            builder.Append(TMinus24hrData.HtmlHeader());
            foreach (var tMinusData in TMinus24HrData)
            {
                if (tMinusData.IsValid())
                {
                    builder.Append(tMinusData.ToHtml());
                }
            }
            builder.Append(TMinus24hrData.HtmlFooter());

            builder.AppendLine();
            builder.AppendLine();

            builder.Append(TPlus24hrData.HtmlHeader());
            foreach (var tPlusData in TPlus24HrData)
            {
                if (tPlusData.IsValid())
                {
                    builder.Append(tPlusData.ToHtml());
                }
            }
            builder.Append(TPlus24hrData.HtmlFooter());

            builder.Append("</body></html>");

            return(builder.ToString());
        }