Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- namespace keywatch
- {
- class Program
- {
- static void Main(string[] args)
- {
- //setup
- string url = "";
- int count = 0;
- int timer = 0;
- string contentprev = "";
- string content = "";
- DateTime date1 = DateTime.Now;
- url = "https://www.codeproject.com/Articles/1041115/Webscraping-with-Csharp";
- timer = 2;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- if (response.StatusCode == HttpStatusCode.OK)
- {
- Stream receiveStream = response.GetResponseStream();
- StreamReader readStream = null;
- if (response.CharacterSet == null)
- {
- readStream = new StreamReader(receiveStream);
- }
- else
- {
- readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
- }
- contentprev = readStream.ReadToEnd();
- response.Close();
- readStream.Close();
- }
- while(true)
- {
- if ((DateTime.Now - date1).TotalSeconds > timer)
- {
- request = (HttpWebRequest)WebRequest.Create(url);
- response = (HttpWebResponse)request.GetResponse();
- if (response.StatusCode == HttpStatusCode.OK)
- {
- Stream newreceiveStream = response.GetResponseStream();
- StreamReader newreadStream = null;
- if (response.CharacterSet == null)
- {
- newreadStream = new StreamReader(newreceiveStream);
- }
- else
- {
- newreadStream = new StreamReader(newreceiveStream, Encoding.GetEncoding(response.CharacterSet));
- }
- content = newreadStream.ReadToEnd();
- response.Close();
- newreadStream.Close();
- }
- //if (!contentprev.Equals(content, StringComparison.Ordinal))
- if(contentprev != content)
- {
- Console.WriteLine("PING");
- contentprev = string.Copy(content);
- }
- date1 = DateTime.Now;
- count++;
- Console.WriteLine(count.ToString());
- }
- }
- }
- }
- }*/
- using HtmlAgilityPack;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Mail;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- namespace keywatch
- {
- class Program
- {
- static void Main(string[] args)
- {
- #region setup
- string url = "";
- int count = 1;
- int timer = 0;
- string contentprev = "";
- string content = "";
- DateTime date1 = DateTime.Now;
- url = "https://keyforge.com/flash/";
- timer = 5;
- #endregion
- #region initial connection and setup
- HtmlWeb web = new HtmlWeb();
- var doc = web.Load(url);
- string docstring = doc.DocumentNode.InnerHtml;
- int index = docstring.IndexOf("Main-content");
- docstring = docstring.Substring(index);
- index = docstring.IndexOf("/section");
- docstring = docstring.Substring(0, index + 9);
- contentprev = String.Copy(docstring);
- #endregion
- #region sms test
- var fromAddress = new MailAddress("SENDEREMAIL", "joojemail");
- var toAddress = new MailAddress("[PHONENNUMBER][PHONEPROVIDERMAILER]", "joojcell");
- const string fromPassword = "[EMAILPW]";
- try
- {
- var smtp = new SmtpClient
- {
- Host = "smtp.gmail.com",
- Port = 587,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
- };
- using (var message = new MailMessage(fromAddress, toAddress) { Subject = "sub", Body = "ject" })
- {
- smtp.Send(message);
- Console.WriteLine("test sent! good luck out there");
- }
- }
- catch(Exception ex)
- {
- Console.WriteLine("fcked it up!");
- }
- #endregion
- #region loop
- while (true)
- {
- if ((DateTime.Now - date1).TotalSeconds > timer)
- {
- try
- {
- doc = web.Load(url);
- docstring = doc.DocumentNode.InnerHtml;
- index = docstring.IndexOf("Main-content");
- docstring = docstring.Substring(index);
- index = docstring.IndexOf("/section");
- docstring = docstring.Substring(0, index + 9);
- content = String.Copy(docstring);
- }
- catch (Exception)
- {
- Console.WriteLine("fcked it up!");
- }
- if (contentprev.Length != content.Length)
- {
- contentprev = string.Copy(content);
- #region looped text
- try
- {
- var smtp = new SmtpClient
- {
- Host = "smtp.gmail.com",
- Port = 587,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
- };
- using (var message = new MailMessage(fromAddress, toAddress) { Subject = "keywatch", Body = "update #" + count.ToString() })
- {
- smtp.Send(message);
- Console.WriteLine("text #" + count.ToString() + " sent. godspeed");
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("fcked it up!");
- }
- #endregion
- }
- date1 = DateTime.Now;
- count++;
- Console.WriteLine(count.ToString());
- }
- }
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement