private UpdateTbl GetId() { var ut = new UpdateTbl(); try { _connection = new MySqlConnection(ConnectionString); _connection.Open(); var query = string.Format("SELECT * from db1305421_wpdev.UpdateTbl where Id like '1';"); using (var cmd = new MySqlCommand(query, _connection)) { using (var r = cmd.ExecuteReader()) { while (r.Read()) { ut.Id = r.GetInt32("UpdateID"); ut.Date = DateTime.Parse(r.GetString("Date")); } } } } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } finally { _connection.Close(); } return(ut); }
public List <Update> GetUpdates(string url) { var updates = new List <Update>(); var ut = new UpdateTbl(); url = "http://www.gaa.ie/modules/live_match.php?id=10830"; var texts = new List <string>(); var time = ""; var score = ""; var web = new HtmlWeb(); HtmlDocument doc; try { var link = url; doc = web.Load(link); var nodes = doc.DocumentNode.SelectNodes("//div[@class='mt_updates']"); //var count = nodes.Count(); var cont = true; foreach (var node in nodes) { cont = true; time = WebUtility.HtmlDecode(node.ChildNodes[0].InnerText); time = Regex.Replace(time, @"\t|\n|\r|<li>|</li>|<ul>|</ul>|<b>|<br>|</b>|<em>|</em>|<u>|</u>|<strong>|</strong>|<p>|</p>", ""); var attr = node.ChildNodes; foreach (var child in attr.Where(a => a.Name == "h4")) { score = WebUtility.HtmlDecode(child.InnerText); score = Regex.Replace(score, @"\t|\n|\r|<li>|</li>|<ul>|</ul>|<b>|<br>|</b>|<em>|</em>|<u>|</u>|<strong>|</strong>|<p>|</p>", ""); } foreach (var child in attr.Where(a => a.Name == "p")) { var text = ""; text = WebUtility.HtmlDecode(child.InnerHtml); text = Regex.Replace(text, @"\t|\r|<li>|</li>|<ul>|</ul>|<b>|<br>|</b>|<em>|</em>|<u>|</u>|<strong>|</strong>|<p>|</p>", ""); if (text == "") { cont = false; } if (text.Contains("Preview")) { cont = false; } if (text.Contains("tweet_box")) { cont = false; } if (text.Contains("youtube_embed")) { cont = false; } texts.Add(text); } if (texts.Count > 0) { var update = new Update(); update.Text = new List <string>(); foreach (var s in texts) { update.Text.Add(s); } update.Time = time; update.Score = score; texts.Clear(); if (cont) { updates.Add(update); } score = ""; time = ""; } } } catch (Exception ex) { var stackFrame = new StackFrame(); var methodBase = stackFrame.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } return(updates); }