Bite my bytes

What I learn by day I blog at night - A blog from Microsoft Consultant working from Ljubljana, Slovenia

  Home :: Contact :: Syndication  
  999 Posts :: 7691 Comments :: 235 Trackbacks


Most popular posts
in last 360 days


My Projects



Copyright © by David Vidmar
Contact me!
LinkedIn Profile

I'll soon have far less free time that I have now, so I'm actively working on simplifying my life. I don't want to give up things, I try to slipstream as much as possible. So far I think I'm doing quite well.

One big time waster was putting together Sunday's regular weekly links. I bookmark stuff I find on excellent delicious using Delicious Firefox buttons. That part is fast and painless, there is nothing I can do to improve that. When creating a post, I basically copy/paste, cleanup and then some formatting. Booooring...

As I grew tired of that, I remembered than delicious has an API that I could use to automate formatting. If I would be just little bit more careful when posting, Sunday evening could be free again. I could use first tag as category, enter a description, so post generation could be completely automatic.

And that's how DeliciousLinks project was born few weeks ago. Since some stuff is hard-coded, the executable is not ready for publishing. But if anyone thinks this could be useful, I'll gladly share the code.


Let's go to some C# code how I done it.... Prepare WebClient object with right credentials.

WebClient webClientDelicious = new WebClient
                                       Encoding = Encoding.Default,
                                       Credentials = new NetworkCredential(username, password)

Get XML of links from particular day. I'll repeat that for all dates in a week.

Uri uriDelicious = new Uri(string.Format("{0:yyyy-MM-dd}", date));
string xmlContent = webClientDelicious.DownloadString(uriDelicious);

Then, using Linq to XML, I sort results and fill data in List<Link>

var posts = from post in xdoc.Descendants("post")
            orderby post.Attribute("tag").Value.Split(' ')[0], post.Attribute("description").Value
            select new Link
                           Url = post.Attribute("href").Value,
                           Title = post.Attribute("description").Value,
                           Description = post.Attribute("extended") == null ? "" : post.Attribute("extended").Value,
                           Category = (post.Attribute("tag").Value.Split(' ')[0]).Capitalize()

I also parse a RSS feed, I also parse that with Linq to XML.

var entries = from feedElements in rssXDocument.Descendants(xmlns + "entry")
              select new Link
                             Url = feedElements.Elements(xmlns + "link")
                                    .Where(link => link.Attribute("rel").Value == "alternate")
                                    .Select(link => link.Attribute("href").Value).First(),
                             Title = feedElements.Element(xmlns + "title").Value,
                             Description = "",
                             Category = "Software Updates"

Then I'll just roll over results, use StringBuilder to build HTML and post body is done.

But where to put this code into? In Windows Live Writer add-in, of course!

First, I add a reference to WindowsLive.Writer.Api. Then I'll create new class that will extend ContentSource.

[WriterPlugin("{06BDBEB7-0D4F-45bf-AD23-2AAE6D98D745}", "Delicious Links",
    ImagePath = "images.delicious_links.png", 
    HasEditableOptions = true, 
    PublisherUrl = "", 
    Description = "Helps to generate link posts using bookmarks on")]
[InsertableContentSource("Delicious Links")]
public class WlwPlugin : ContentSource
    Settings settings;
    public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
        DialogResult dialogResult;
        using (MainForm mainForm = new MainForm(settings.Username, settings.Password))
            dialogResult = mainForm.ShowDialog();
            if (dialogResult == DialogResult.OK)
                content = mainForm.Links;
        return dialogResult;            
    // ... some more boring code to read and write settings ...

All done! I can get my weekly links post with couple of clicks exactly where I need them. I love it.

This is how my Windows Live Writer looks like now.



Technorati tags: , , ,
Posted on Wednesday, March 05, 2008 9:37 PM | Filed under: Software Developement Internet |
Comments have been closed on this topic.