Every 20 mins it checks if there was a new post at a url which is pasted in a textbox. If the textbox is empty it checks for a file located in the same directory as it for the url, if not it uses Gaiidens journal as the default.
if (textBoxUrl.Text == "") { if (File.Exists(infFilePath)) { var urlFromFile = System.IO.File.ReadAllText(infFilePath); textBoxUrl.Text = urlFromFile; return (urlFromFile == "") ? "https://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=251283" : urlFromFile; } else { textBoxUrl.Text = "https://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=251283"; return textBoxUrl.Text ;} } else return textBoxUrl.Text;
It then checks if there have been any new comments since the last check.
var currentCheck = (currentCheckInit.Count > checkCompare.Count) && checkCompare.Count>0 ? currentCheckInit.Skip(currentCheckInit.Count - checkCompare.Count).ToList() : currentCheckInit; var sb = new StringBuilder(); if (currentCheck.Sum(p => p.CommentCount) != checkCompare.Sum(p => p.CommentCount)) { for (int i = 0; i < checkCompare.Count; i++) { if (currentCheck.IsComment && currentCheck.CommentCount != checkCompare.CommentCount) { var msg = "At " + DateTime.Now.ToShortTimeString() + " Found " + (currentCheck.CommentCount - checkCompare.CommentCount) + " New Comment(s) in thread, " + checkCompare.Title;<br> listBoxLog.Items.Add(msg);<br> sb.AppendLine(msg);<br> newComment = <span class="cpp-keyword">true</span>;<br> notifyIcon1.Text = <span class="cpp-literal">"New Comment(s) found"</span>;<br> }<br> }<br> }<br><br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>You can also save the last query results to disk. Then later on you may download from the site and check against disk so the program doesnt have to run continuosly to be useful.<br><br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre> <span class="cpp-keyword">private</span> <span class="cpp-keyword">void</span> buttonSaveState_Click(object sender, EventArgs e)<br> {<br> var sb = <span class="cpp-keyword">new</span> StringBuilder();<br> oldCheck.ForEach(entry => sb.AppendLine (entry.CommentCount + <span class="cpp-literal">"|"</span>+entry.IsComment + <span class="cpp-literal">"|"</span> +entry.Title));<br> File.WriteAllText(statePath, sb.ToString()); <br> }<br><br> <span class="cpp-keyword">private</span> <span class="cpp-keyword">void</span> buttonCompareStates_Click(object sender, EventArgs e)<br> {<br> var urlFromFile = System.IO.File.ReadAllText(infFilePath);<br> <span class="cpp-keyword">if</span> ((urlFromFile != textBoxUrl.Text) && textBoxUrl.Text != <span class="cpp-literal">""</span>)<br> MessageBox.Show(<span class="cpp-literal">"Warning Url found in file and in textbox do not match. This *may* cause discrapncies."</span>,<br> <span class="cpp-literal">"Are you Sure you know what you are doing?"</span>,<br> MessageBoxButtons.OK, MessageBoxIcon.Warning);<br> var tmpCheck = <span class="cpp-keyword">new</span> List<JournalEntry>();<br> var dat = File.ReadAllLines(statePath).ToList ();<br> dat.ForEach(item => { var s = item.Split('|');<br> var newE = <span class="cpp-keyword">new</span> JournalEntry();<br> newE.CommentCount = <span class="cpp-keyword">int</span>.Parse(s[<span class="cpp-number">0</span>]);<br> newE.IsComment = <span class="cpp-keyword">bool</span>.Parse(s[<span class="cpp-number">1</span>]);<br> newE.Title = s[<span class="cpp-number">2</span>]; <br> tmpCheck.Add(newE); });<br> var currentCheck = util.PollGDNEt(CheckUrlOptions());<br> inited = <span class="cpp-keyword">true</span>;<br> DoComparison(currentCheck, tmpCheck);<br> }<br><br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>The part that scrapes the page is here <br><br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><span class="cpp-keyword">public</span> <span class="cpp-keyword">static</span> List<JournalEntry> PollGDNEt(string url)<br> {<br> HtmlWeb page = <span class="cpp-keyword">new</span> HtmlWeb(); <br> HtmlDocument doc = page.Load(url); <br> var xdoc = doc.ToXDocument();<br><br> var queryResults = from element in xdoc.Descendants()<br> where element.HasAttributes <br> && element.Name.LocalName == <span class="cpp-literal">"span"</span><br> && (element.FirstAttribute.Value == <span class="cpp-literal">"regularfont"</span> || (element.FirstAttribute.Value == <span class="cpp-literal">"smallfont"</span> && element.Value.Contains(<span class="cpp-literal">"Comments"</span>)))<br> select <span class="cpp-keyword">new</span> {Title = element.Value, <br> IsComment = element.FirstAttribute.Value == <span class="cpp-literal">"smallfont"</span>, <br> Count = element.FirstAttribute.Value == <span class="cpp-literal">"smallfont"</span> ? <br> <span class="cpp-keyword">int</span>.Parse( Regex.Match( element.Value, @<span class="cpp-literal">"\d+"</span>).Value ) : <span class="cpp-number">0</span> };<br> var Entries = <span class="cpp-keyword">new</span> List<JournalEntry>();<br> foreach (var result in queryResults)<br> {<br> var entry = <span class="cpp-keyword">new</span> JournalEntry (); <br> entry.CommentCount = result.Count; entry.IsComment = result.IsComment ; entry.Title = result.Title ;<br> Entries.Add(entry);<br> }<br> <span class="cpp-keyword">return</span> Entries;<br> }<br><br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>Full Source is <a href = "http://svn.xp-dev.com/svn/dynamic_jester_Jargon_Flies_Repository2/gdjournal_comments/GameDevJournalCommentator/">here (svn)</a> or <a href = "http://svn.xp-dev.com/svn/dynamic_jester_Jargon_Flies_Repository2/gdjournal_comments/GameDevJournalCommentator.rar">source rar'd</a>. And app is <a href = "http://svn.xp-dev.com/svn/dynamic_jester_Jargon_Flies_Repository2/gdjournal_comments/GameDevJournalCommentator/bin/Debug/gdevj.rar">here (requires .NET 3.5)</a>. Some stats in order of # comments found on page:<br><pre><b><br>User | Total comments on Page | Avg Comments Per Post | Total Posts</b><br>——————————————————————————————————-<br>TrapperZoid 20 4 5<br>Drew 19 1.27 15<br>Talestyn 16 1.07 15<br>Ben 16 2 8<br>Ravuya 16 1.14 14<br>Me 6 1.2 5<br></pre><br><hr> Also Mike P if I you read this and I could get the source for your line counter project, would be cool.<div>
</div>