Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. /*using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Timers;
  8.  
  9. namespace keywatch
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. //setup
  16. string url = "";
  17. int count = 0;
  18. int timer = 0;
  19. string contentprev = "";
  20. string content = "";
  21.  
  22.  
  23. DateTime date1 = DateTime.Now;
  24. url = "https://www.codeproject.com/Articles/1041115/Webscraping-with-Csharp";
  25. timer = 2;
  26.  
  27. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  28. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  29.  
  30. if (response.StatusCode == HttpStatusCode.OK)
  31. {
  32. Stream receiveStream = response.GetResponseStream();
  33. StreamReader readStream = null;
  34.  
  35. if (response.CharacterSet == null)
  36. {
  37. readStream = new StreamReader(receiveStream);
  38. }
  39. else
  40. {
  41. readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
  42. }
  43.  
  44. contentprev = readStream.ReadToEnd();
  45.  
  46. response.Close();
  47. readStream.Close();
  48. }
  49.  
  50. while(true)
  51. {
  52. if ((DateTime.Now - date1).TotalSeconds > timer)
  53. {
  54. request = (HttpWebRequest)WebRequest.Create(url);
  55. response = (HttpWebResponse)request.GetResponse();
  56.  
  57. if (response.StatusCode == HttpStatusCode.OK)
  58. {
  59. Stream newreceiveStream = response.GetResponseStream();
  60. StreamReader newreadStream = null;
  61.  
  62. if (response.CharacterSet == null)
  63. {
  64. newreadStream = new StreamReader(newreceiveStream);
  65. }
  66. else
  67. {
  68. newreadStream = new StreamReader(newreceiveStream, Encoding.GetEncoding(response.CharacterSet));
  69. }
  70.  
  71. content = newreadStream.ReadToEnd();
  72.  
  73. response.Close();
  74. newreadStream.Close();
  75. }
  76.  
  77. //if (!contentprev.Equals(content, StringComparison.Ordinal))
  78. if(contentprev != content)
  79. {
  80. Console.WriteLine("PING");
  81.  
  82. contentprev = string.Copy(content);
  83. }
  84.  
  85. date1 = DateTime.Now;
  86. count++;
  87. Console.WriteLine(count.ToString());
  88. }
  89. }
  90. }
  91.  
  92. }
  93. }*/
  94.  
  95. using HtmlAgilityPack;
  96. using System;
  97. using System.Collections.Generic;
  98. using System.IO;
  99. using System.Linq;
  100. using System.Net;
  101. using System.Net.Mail;
  102. using System.Text;
  103. using System.Threading.Tasks;
  104. using System.Timers;
  105.  
  106. namespace keywatch
  107. {
  108. class Program
  109. {
  110. static void Main(string[] args)
  111. {
  112. #region setup
  113. string url = "";
  114. int count = 1;
  115. int timer = 0;
  116. string contentprev = "";
  117. string content = "";
  118.  
  119. DateTime date1 = DateTime.Now;
  120. url = "https://keyforge.com/flash/";
  121. timer = 5;
  122.  
  123. #endregion
  124.  
  125. #region initial connection and setup
  126.  
  127. HtmlWeb web = new HtmlWeb();
  128. var doc = web.Load(url);
  129. string docstring = doc.DocumentNode.InnerHtml;
  130. int index = docstring.IndexOf("Main-content");
  131. docstring = docstring.Substring(index);
  132. index = docstring.IndexOf("/section");
  133. docstring = docstring.Substring(0, index + 9);
  134. contentprev = String.Copy(docstring);
  135.  
  136. #endregion
  137.  
  138. #region sms test
  139. var fromAddress = new MailAddress("SENDEREMAIL", "joojemail");
  140. var toAddress = new MailAddress("[PHONENNUMBER][PHONEPROVIDERMAILER]", "joojcell");
  141. const string fromPassword = "[EMAILPW]";
  142.  
  143. try
  144. {
  145. var smtp = new SmtpClient
  146. {
  147. Host = "smtp.gmail.com",
  148. Port = 587,
  149. EnableSsl = true,
  150. DeliveryMethod = SmtpDeliveryMethod.Network,
  151. UseDefaultCredentials = false,
  152. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  153. };
  154.  
  155. using (var message = new MailMessage(fromAddress, toAddress) { Subject = "sub", Body = "ject" })
  156. {
  157. smtp.Send(message);
  158. Console.WriteLine("test sent! good luck out there");
  159. }
  160. }
  161. catch(Exception ex)
  162. {
  163. Console.WriteLine("fcked it up!");
  164. }
  165.  
  166. #endregion
  167.  
  168. #region loop
  169.  
  170. while (true)
  171. {
  172. if ((DateTime.Now - date1).TotalSeconds > timer)
  173. {
  174. try
  175. {
  176. doc = web.Load(url);
  177. docstring = doc.DocumentNode.InnerHtml;
  178. index = docstring.IndexOf("Main-content");
  179. docstring = docstring.Substring(index);
  180. index = docstring.IndexOf("/section");
  181. docstring = docstring.Substring(0, index + 9);
  182. content = String.Copy(docstring);
  183. }
  184. catch (Exception)
  185. {
  186.  
  187. Console.WriteLine("fcked it up!");
  188. }
  189.  
  190.  
  191. if (contentprev.Length != content.Length)
  192. {
  193. contentprev = string.Copy(content);
  194.  
  195. #region looped text
  196. try
  197. {
  198. var smtp = new SmtpClient
  199. {
  200. Host = "smtp.gmail.com",
  201. Port = 587,
  202. EnableSsl = true,
  203. DeliveryMethod = SmtpDeliveryMethod.Network,
  204. UseDefaultCredentials = false,
  205. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  206. };
  207.  
  208. using (var message = new MailMessage(fromAddress, toAddress) { Subject = "keywatch", Body = "update #" + count.ToString() })
  209. {
  210. smtp.Send(message);
  211. Console.WriteLine("text #" + count.ToString() + " sent. godspeed");
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. Console.WriteLine("fcked it up!");
  217. }
  218. #endregion
  219. }
  220.  
  221. date1 = DateTime.Now;
  222. count++;
  223. Console.WriteLine(count.ToString());
  224. }
  225. }
  226.  
  227. #endregion
  228. }
  229.  
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement