6 |
using System.Linq; |
using System.Linq; |
7 |
using System.Xml.Linq; |
using System.Xml.Linq; |
8 |
using System.Diagnostics; |
using System.Diagnostics; |
9 |
|
using libhtmlscrapper; |
10 |
|
|
11 |
namespace libThermoControl |
namespace libThermoControl |
12 |
{ |
{ |
20 |
|
|
21 |
public static int ExternalTemp { get { return GetExternalTemp(); } } |
public static int ExternalTemp { get { return GetExternalTemp(); } } |
22 |
|
|
23 |
|
public static readonly string WEATHER_URL = ""; // 60 |
24 |
public static readonly string THERMISTAT_DEVICE = ""; // 60 |
public static readonly string THERMISTAT_DEVICE = ""; // 60 |
25 |
public static readonly int MIN_TEMP = 0; // 60 |
public static readonly int MIN_TEMP = 0; // 60 |
26 |
public static readonly int MAX_TEMP = 0; // 90 |
public static readonly int MAX_TEMP = 0; // 90 |
111 |
|
|
112 |
static int GetExternalTemp() |
static int GetExternalTemp() |
113 |
{ |
{ |
114 |
return 0; |
int temp = 0; |
115 |
|
List<string> BannedLinks = new List<string>(); |
116 |
|
using (GenericScrapper scrapper = new GenericScrapper(WEATHER_URL, true, BannedLinks, false, true)) |
117 |
|
{ |
118 |
|
scrapper.BannedHTMLLinks = BannedLinks; |
119 |
|
scrapper.GetUrlsToDownload += scrapper_GetUrlsToDownload; |
120 |
|
scrapper.CreateDownloadUrls(); |
121 |
|
if (scrapper.UrlsToDownload.Count > 0) |
122 |
|
{ |
123 |
|
var t = scrapper.UrlsToDownload.FirstOrDefault(); |
124 |
|
if (t != null && t.Tag != null) |
125 |
|
{ |
126 |
|
try |
127 |
|
{ |
128 |
|
int k = Convert.ToInt32(t.Tag); |
129 |
|
temp = k; |
130 |
|
} |
131 |
|
catch (Exception ex) |
132 |
|
{ |
133 |
|
temp = 0; |
134 |
|
} |
135 |
|
} |
136 |
|
} |
137 |
|
} |
138 |
|
return temp; |
139 |
|
} |
140 |
|
|
141 |
|
static void scrapper_GetUrlsToDownload(out List<URLLink> UrlsToDownload, GenericScrapper scrapper) |
142 |
|
{ |
143 |
|
UrlsToDownload = new List<URLLink>(); |
144 |
|
StreamReader sr = scrapper.HTMLReader; |
145 |
|
while (!sr.EndOfStream) |
146 |
|
{ |
147 |
|
string line = sr.ReadLine(); |
148 |
|
if (line.ToLower().Contains(string.Format("<tr class=\"pre\">").ToLower())) |
149 |
|
{ |
150 |
|
line = sr.ReadLine(); |
151 |
|
if (line.ToLower().Contains(string.Format("<th scope=\"row\">Now</th>").ToLower())) |
152 |
|
{ |
153 |
|
line = sr.ReadLine(); |
154 |
|
if (line.ToLower().Contains(string.Format("<td>").ToLower())) |
155 |
|
{ |
156 |
|
//Console.WriteLine("Found: {0}", line); |
157 |
|
string raw_line = line; |
158 |
|
raw_line = raw_line.Replace("<td>", "").Replace("</td>", "").Replace("°",""); |
159 |
|
raw_line = raw_line.Trim(); |
160 |
|
//Console.WriteLine("Found Raw: {0}", line); |
161 |
|
Console.WriteLine("Found Parsed: {0}", raw_line); |
162 |
|
UrlsToDownload.Add(new URLLink("Now", new Uri(scrapper.URL), raw_line)); |
163 |
|
break; |
164 |
|
} |
165 |
|
} |
166 |
|
} |
167 |
|
} |
168 |
|
sr.Close(); |
169 |
} |
} |
170 |
} |
} |
171 |
} |
} |