Tim Hibbard

CEO for EnGraph software
posts - 626, comments - 1586, trackbacks - 459

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
Gravatar

# re: Simple class to parse Twitter with LINQ

Thank you for sharing this valuable information. I hope everyone will also find it very helpful. Keep posting!
5/4/2011 11:13 PM | internet marketing product revie
Gravatar

# re: Simple class to parse Twitter with LINQ

LINQ address the current database development model in the context of Object Oriented Programming Model. If some one wants to develop database application on .Net platform the very simple approach he uses ADO.Net. ADO.Net is serving as middle ware in application and provides complete object oriented wrapper around the database SQL.
5/26/2011 5:28 AM | Fertility Jewelry
Gravatar

# # re: Simple class to parse Twitter with LINQ

A friend often reminds me about this website but in fact this is the very first page I have checked out so far. I am highly pleased and right now an aficionado. Well I am adding this RSS to my e-mail and could look forward for much more of your respective intriguing content. Make sure you update this again soon.
7/7/2011 2:10 AM | 4Hour Body
Gravatar

# re: Simple class to parse Twitter with LINQ

Twitter is one of the best social networking site these days. Everyone is indulged in this. Twitter with Linq will work so nicely.
11/24/2011 11:50 PM | Employment news
Gravatar

# re: Simple class to parse Twitter with LINQ

Thank you for sharing this information. I was looking this type of post for a long time.
4/11/2012 6:17 AM | Kitap
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: