Tim Hibbard

Software Architect for EnGraph software
posts - 611, comments - 539, trackbacks - 469

My Links

News



Add to Google




Twitter












Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

EnGraph Blogs

Links

Other

Roll

Simple class to parse Twitter with LINQ

In ParaPlan 4.0, we use twitter to maintain a change log.  I wanted to display this information to our users, so I wrote a little class that calls the RSS feed and uses LINQ to parse the data.  All I need is the message and the date, so that is all it pulls out.

Here is the class:

public class Twitter
{
    public string Message { get; set; }
    public DateTime PubDate { get; set; }
 
    public static List<Twitter> Parse(string User)
    {
        var rv = new List<Twitter>();
        var url = "http://twitter.com/statuses/user_timeline/" + User + ".rss";
 
        var element = XElement.Load(url);
        foreach (var node in element.Element("channel").Elements("item"))
        {
            var twit = new Twitter();
            var message = node.Element("description").Value;
            //remove username information
            twit.Message = message.Replace(User + ": ", string.Empty);
            twit.PubDate = DateTime.Parse(node.Element("pubDate").Value);
            rv.Add(twit);
        }
 
        return rv;
 
    }
}

Our calling code looks like this:

var changes = new List<string>();
 
var fromTwitter = Twitter.Parse("ParaPlan");
fromTwitter.ForEach(t =>
    changes.Add(t.PubDate.ToString("MM/dd/yy") + " - " + t.Message));
 
var list = new ListBox();
 
list.ItemsSource = changes;

 

Technorati Tags: ,,,,

Print | posted on Monday, January 05, 2009 2:53 PM | Filed Under [ .NET Goldstar WPF ]

Feedback

Gravatar

# re: Simple class to parse Twitter with LINQ

Sweet dude! I really got to get to work on WMTwit.
1/6/2009 9:37 PM | Robz
Gravatar

# re: Simple class to parse Twitter with LINQ

Ah, yes. Parsing twitter! I concur. :)
2/25/2009 12:23 AM | Chelsea
Gravatar

# re: Simple class to parse Twitter with LINQ

Interesting - I've also seen a lot of posts about LinqToTwitter recently -http://www.codeplex.com/LinqToTwitter

If nothing else, I love the name!
3/20/2009 3:16 AM | Stuart

Post Comment

Title  
Name  
Email
Url
Comment   

Powered by: