/[ThermoControl]/trunk/libThermoControl/Configuration.cs
ViewVC logotype

Diff of /trunk/libThermoControl/Configuration.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libThermoControl/Configuration.cs	2013/11/13 02:22:43	20
+++ trunk/libThermoControl/Configuration.cs	2013/11/13 03:08:55	25
@@ -6,6 +6,7 @@
 using System.Linq;
 using System.Xml.Linq;
 using System.Diagnostics;
+using libhtmlscrapper;
 
 namespace libThermoControl
 {
@@ -17,6 +18,9 @@
         
         public static int CurrentTemp { get { return ReadTemp(); } set { WriteTemp(value); } }
 
+        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
@@ -71,7 +75,7 @@
             {
                 using (BinaryWriter bw = new BinaryWriter(fs))
                 {
-                    bw.Write(temp);
+                    bw.Write((byte)temp);
                     bw.Flush();
                     bw.Close();
                 }
@@ -98,11 +102,70 @@
             {
                 using (BinaryReader br = new BinaryReader(fs))
                 {
-                    temp = br.ReadInt32();
+                    temp = br.ReadByte();
                     br.Close();
                 }
             }
             return temp;
         }
+
+        static int GetExternalTemp()
+        {
+            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("&deg;","");
+                            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