public void GetICOs(string dbfile, string logfile) { HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load("https://icodrops.com/category/upcoming-ico/"); List <ICODetails> result = new List <ICODetails>(); var icolist = doc.DocumentNode.SelectNodes("//div[@id='upcoming_ico']").ToList(); foreach (var ico in icolist) { string name = ico.SelectSingleNode(".//h3/a").InnerText; string interest = ico.SelectSingleNode(".//div[@class='interest']").InnerText.Trim('\r', '\t', '\n'); if (name == "") { } ICODetails temp = AddorUpdateICO(dbfile, name, interest); if (temp.Name != null) { result.Add(temp); } } if (result.Count > 0) { SendNotification(result); } LogSuccess(result.Count, logfile); }
public ICODetails AddorUpdateICO(string dbfile, string name, string interest) { ICODetails icodetails = new ICODetails(); using (SQLiteConnection conn = new SQLiteConnection("data source=" + dbfile)) { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { string selectQuery = "SELECT COUNT(*) FROM ICO WHERE Name = '" + name + "'"; cmd.CommandText = selectQuery; int count = Convert.ToInt32(cmd.ExecuteScalar()); string query = ""; if (count > 0) { selectQuery = "SELECT Rating FROM ICO WHERE Name = '" + name + "'"; cmd.CommandText = selectQuery; string oldrating = cmd.ExecuteScalar().ToString(); if (oldrating != interest) { query = "UPDATE ICO SET Rating='" + interest + "',UpdatedDate='" + GetTime().ToShortDateString() + "' WHERE Name='" + name + "'"; cmd.CommandText = query; cmd.ExecuteNonQuery(); icodetails.Name = name; icodetails.NewRating = interest; icodetails.OldRating = oldrating; } } else { query = "INSERT INTO ICO (Name,Rating,UpdatedDate) VALUES ('" + name + "','" + interest + "','" + GetTime().ToShortDateString() + "')"; cmd.CommandText = query; cmd.ExecuteNonQuery(); icodetails.Name = name; icodetails.NewRating = interest; icodetails.OldRating = interest; } } conn.Clone(); } return(icodetails); }