Click here to Skip to main content
15,115,261 members
Articles / Web Development / HTML
Article
Posted 22 Jul 2021

Tagged as

Stats

2.6K views
58 downloads
1 bookmarked

Article Stats Tracker

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
22 Jul 2021CPOL5 min read
A simple application that keeps track of your CodeProject article statistics
This app loads any Author List of Articles you tell it to, parses the HTML file's information and reports which articles are being viewed, bookmarked or downloaded.

Image 1

Introduction

When you have no friends, no social life and all you care for are clicks, views and likes.... it's just a little sad.

But if you're a professional lounger, such as myself, and have nothing better to do with your time but watch numbers remind you how much you need to get out more often, then I've got just the thing.

The only reason I have no social life is because I stay at home and write apps and articles about them (not to mention my introspective 'I don't care' character flaws). If you have no life of your own, this will help you while-away the time as you admire your own writing skills (real or imagined) being reflected back to you in this statistical mirror as a vanity to compensate for your want of friends. You just might discover the devastating truth about the sad measure of your worth. Unless you have friends, family and people who love you, in which case, never mind all that.

The App

Image 2

The image above shows you the latest report for my list of articles. Apparently, someone just downloaded a copy of The Game of Clue and is now happily sleuthing about the Bawdy Mansion asking whether Mrs.Peacock was in the Ballroom with the Wrench. When you first run it, the default URL is set to my own, so if you want to see yours you'll need to summon the ContextMenu and click on setURL.

And a groupbox will appear where you can cut-n-paste the Code-Project Author's Article List (find it by clicking on the My Articles selection that appears below your name at the top right of this page). You paste the appropriate URL into the textbox and click ok. The first time you load it, the app will not report any changes as it has never seen that page before. You can see in the image below that there are a few files in the Bin/Debug/ directory (working directory) with suspicious looking XML files. This is where the information about your articles is stored. When you have tried several different authors article lists, they each have their own XML file and the app will provide you with a list of names you can select in the ListBox below the URL input textbox. When you click on a name in that listbox, that author's articles are loaded, compared and changes reported.

When you run this app, you'll notice that the Views statistics are always incremented by multiples of 10 but have no fear, there are no click-farms lurking in Code-Projects annals viewing your articles in multiples of tens just to try to make you feel like you actually have a readership with an artificially inflated Views-count.... no, no, no. What is happening here, is that the views are being correctly tallied and the web-page with all your articles gets updated only when they've reached a minimum count of ten. Vladimir Putin had nothing to do with this one.

Image 3

The Menu Options are straight forward.

Image 4

  • Refresh - reload the selected Author's articles and update the output
  • set Delay - change the delay time between automatic updates
  • set URL - enter a new URL
  • set Toggles - lets you choose which fields you want reported
  • clear - erases the text in the RichTextBox (rtx will be saved and reloaded at run time)
  • Hide - hides the form until an update results in changes to your statistics. You can alternately use the CTRL-PrntScrn key to toggle the form's Visible property.
  • TopMost - keeps the app's form in your Windows foreground when checked
  • exit - I almost called this Egress but, unlike P.T.Barnum, I didn't see the profit in it.

Using the Code

There's nothing really complicated about this app. I've been using something I call the HTML-ator to figure out what I need to do to HTML files in order to extract the data I want from a website. Using this tool, I parsed out the HTML files, extracted the Article statistics and stored them into a list of classArticle objects that keep track of their statistics. These articles are stored in a binary tree using their Titles as search keys, then recorded to XML file when the selected Author is changed.

Here's some of the code that parses out the HTML taken from classURL's

public List<classArticleChanges> GetReports() method.

It defines the ending of an HTML tag which appears before each article's information. Then it finds instances of this HTML tag and takes out the chunks of HTML which tell your web-browser how to draw the statistics for each article.

C#
string strArticle_Field_Start = "<tr id=";
string strArticle_Field_End = "MainArticleRow\" valign=\"top\">";

int intArticleIndex_End = strHTML_Source.IndexOf(strArticle_Field_End);

int intArticleIndex_Start = intArticleIndex_End;
int intTemp = 0;
string strDebug = "";
int intBest = strHTML_Source.IndexOf(strArticle_Field_Start);
while (intTemp >= 0 && intTemp < intArticleIndex_End)
{
    intTemp = strHTML_Source.IndexOf(strArticle_Field_Start, intTemp + 1);
    strDebug = intTemp >= 0
                            ? strHTML_Source.Substring(intTemp, 130)
                            : "";
    if (intTemp >= 0 && intTemp < intArticleIndex_End)
        intBest = intTemp;
}
intArticleIndex_Start = intBest;
                        
strDebug = intBest >= 0
                    ? strHTML_Source.Substring(intBest, 130)
                    : "";
            
while (intArticleIndex_Start >= 0 && intArticleIndex_End > intArticleIndex_Start)
{
    string strHTML_Article = classStringLibrary.HTML_GetNext
           (strHTML_Source, "<tr", "</tr>", intArticleIndex_Start);
    strHTML_Source = strHTML_Source.Replace(strHTML_Article, "");
    List<classArticle_Field> lstFields = classArticle.getFields(strHTML_Article);
    if (lstFields != null)
    {
        classArticle cArticle = classArticle.Tree_Search
                                ((string)lstFields[(int)enuArticleFields.Title].value);
        if (cArticle == null)
        {
            cArticle = new classArticle();
            cArticle.lstFields_Current
                = cArticle.lstFields_Next
                = lstFields;
            classArticle.Tree_Insert(ref cArticle);
        }
        lstArticles.Add(cArticle);

        cArticle.lstFields_Current = cArticle.lstFields_Next;
        cArticle.lstFields_Next = lstFields;

Then, in the While-Loop section a little further down, the call to

C#
string strHTML_Article = 
  classStringLibrary.HTML_GetNext(strHTML_Source, "<tr", "</tr>", intArticleIndex_Start);

extracts the HTML for each article and that article's different 'fields' of statistics are extracted by this next call which removes all HTML-tags, slims down the results text until it look like English and then parses out the related statistics into a list.

C#
List<classArticle_Field> lstFields = classArticle.getFields(strHTML_Article);

The Articles binary-tree is then searched for an existing instance of classArticle using the Title field in the lstFields. If no article of that name is found in the tree, one is created and inserted into the tree with the new list of statistics set as the 'old' data as well as the 'new' data and no changes will be recorded this time around. If an article is found in the tree, its old data is compared with the new data and any changes in these statistics are put to the screen.

Points of Interest

No... there wasn't much to it. I haven't done any hard-core 'trying to crash this thing' sort of testing but its been stable for a few days, so it should be fine.

History

  • 21st July, 2021: Article published

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University. He is unemployable and currently living in Moncton, N.B. writing his next novel.

Comments and Discussions

 
QuestionI did something like this a while back Pin
Sacha Barber26-Jul-21 22:48
mvaSacha Barber26-Jul-21 22:48 
AnswerRe: I did something like this a while back Pin
Christ Kennedy30-Jul-21 4:16
mvaChrist Kennedy30-Jul-21 4:16 
cool.
vanity sure gives one a warm-fuzzy feeling doesn't it... Wink | ;)
my code is perfect until i don't find a bug...

QuestionSome odd behaviors Pin
Marc Clifton23-Jul-21 7:27
mvaMarc Clifton23-Jul-21 7:27 
AnswerRe: Some odd behaviors Pin
Christ Kennedy24-Jul-21 2:27
mvaChrist Kennedy24-Jul-21 2:27 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA22-Jul-21 20:43
professionalȘtefan-Mihai MOGA22-Jul-21 20:43 
GeneralRe: My vote of 5 Pin
Christ Kennedy23-Jul-21 0:58
mvaChrist Kennedy23-Jul-21 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.