Parent Directory
|
Revision Log
|
Patch
--- trunk/libThermoControl/Configuration.cs 2013/11/13 02:43:01 22 +++ trunk/libThermoControl/Configuration.cs 2013/11/13 03:08:40 24 @@ -6,6 +6,7 @@ using System.Linq; using System.Xml.Linq; using System.Diagnostics; +using libhtmlscrapper; namespace libThermoControl { @@ -19,6 +20,7 @@ public static int ExternalTemp { get { return GetExternalTemp(); } } + public static readonly string WEATHER_URL = ""; // 60 public static readonly string THERMISTAT_DEVICE = ""; // 60 public static readonly int MIN_TEMP = 0; // 60 public static readonly int MAX_TEMP = 0; // 90 @@ -109,7 +111,61 @@ static int GetExternalTemp() { - return 0; + int temp = 0; + List<string> BannedLinks = new List<string>(); + using (GenericScrapper scrapper = new GenericScrapper(WEATHER_URL, true, BannedLinks, false, true)) + { + scrapper.BannedHTMLLinks = BannedLinks; + scrapper.GetUrlsToDownload += scrapper_GetUrlsToDownload; + scrapper.CreateDownloadUrls(); + if (scrapper.UrlsToDownload.Count > 0) + { + var t = scrapper.UrlsToDownload.FirstOrDefault(); + if (t != null && t.Tag != null) + { + try + { + int k = Convert.ToInt32(t.Tag); + temp = k; + } + catch (Exception ex) + { + temp = 0; + } + } + } + } + return temp; + } + + static void scrapper_GetUrlsToDownload(out List<URLLink> UrlsToDownload, GenericScrapper scrapper) + { + UrlsToDownload = new List<URLLink>(); + StreamReader sr = scrapper.HTMLReader; + while (!sr.EndOfStream) + { + string line = sr.ReadLine(); + if (line.ToLower().Contains(string.Format("<tr class=\"pre\">").ToLower())) + { + line = sr.ReadLine(); + if (line.ToLower().Contains(string.Format("<th scope=\"row\">Now</th>").ToLower())) + { + line = sr.ReadLine(); + if (line.ToLower().Contains(string.Format("<td>").ToLower())) + { + //Console.WriteLine("Found: {0}", line); + string raw_line = line; + raw_line = raw_line.Replace("<td>", "").Replace("</td>", "").Replace("°",""); + raw_line = raw_line.Trim(); + //Console.WriteLine("Found Raw: {0}", line); + Console.WriteLine("Found Parsed: {0}", raw_line); + UrlsToDownload.Add(new URLLink("Now", new Uri(scrapper.URL), raw_line)); + break; + } + } + } + } + sr.Close(); } } }
ViewVC Help | |
Powered by ViewVC 1.1.22 |