Home > .NET > Extract Favorite Websites Collection from Bookmark RSS feeds

Extract Favorite Websites Collection from Bookmark RSS feeds

February 25th, 2007

Bookmarking a website and bookmarking an article are different usage of the bookmarking tools. You may want to have a clean collection of all your favorite websites and on the other hand you may want to bookmark multiple good articles from the same website. This way your bookmark collection is a mixture of both. This is my little frustration of using sites like http://del.icio.us/. It’s great in collect articles and links, but not so great to keep a clean list of my favorite websites. Although I can use a different bookmarking tool (e.g., http://favorites.live.com/, which could sync with IE bookmarks) to collect just sites, it’d be nice if I could keep them in one place. So I developed a custom web control that could be put on your website to display all the websites of a list of http://del.icio.us/ RSS feeds in the order of popularity. Multiple articles of each websites are collapsed into one entry shown for that website, and the number of the articles bookmarked from that site is used as the indicator of the popularity of that site within the RSS feeds. So the more articles of a website that are bookmarked, the more popular the website is. In my example of using this web control, I put my bookmark feeds and the del.icios.us homepage hotlist feeds in so that I will get a list of all the websites either I bookmarked or on the hostlist.

<cc1:BookmarkedWebsites
    id
="WebCustomControl1_1"
    Url
="http://del.icio.us/rss/dbtu/; http://del.icio.us/rss/"
    runat
="server"></cc1:BookmarkedWebsites>

The "Url" property of the control specifies a list of RSS feeds to extract from. The delimiter is ";".

RSS.NET library is used to parse the RSS feed. The website part (domain) of the URL is extracted and used as the collapsing key.

protected override void RenderContents(HtmlTextWriter output)
{
    // Get each individual RSS feed
    char
[] delimiters = { ‘;’ };
    string[] feeds = Url.Split(delimiters);
   
    // Get all websites
    SortedDictionary
<string, int> sites =
        new
SortedDictionary<string, int>();
    foreach (string feedUrl in feeds)
    {
        RssFeed feed = RssFeed.Read(feedUrl);
        foreach (RssChannel channel in feed.Channels)
        {
            foreach (RssItem item in channel.Items)
            {
                string link = item.Link.Scheme + "://" +
                    item.Link.Host;
                if (sites.ContainsKey(link))
                {
                    sites[link]++;
                }
                else
                {
                    sites[link] = 1;
                }
            }
        }
    }

    // Reorder it on the number of occurrence (thus popularity)
    KeyValuePair
<string, int>[] popSites =
        new
KeyValuePair<string,int>[sites.Count];
    sites.CopyTo(popSites, 0);
    Array.Sort(popSites, new SitePopularityComparer());
    foreach (KeyValuePair<string, int> s in popSites)
    {
        output.Write("( " + s.Value + " ) <a href=\"" +
            s.Key + "\">"+ s.Key + "</a><br />");
    }
}

public class SitePopularityComparer : IComparer
{
    int IComparer.Compare(object x, object y)
    {
        return ((KeyValuePair<string, int>)y).Value -
                ((KeyValuePair<string, int>)x).Value;
    }
}

The web control looks like the following:

 

Furthermore, it would be cooler to be able to sync this website list into the browser bookmark so that you can use them as your reading list even more conveniently.

The prototype source code can be downloaded here: MyFavoriteWebSites.zip.

.NET , , , ,

  1. No comments yet.
  1. No trackbacks yet.