Geeks With Blogs
Paul's development blog Tidbits from Smart Client, Windows Forms, C#, .NET 2.0, XML, and related toys...

Get a count and percentage of how many updates you've had with each twitter tool.

Download C# 3.5 WPF Source Code
Note: This source code is mostly a quick hack to get the data I wanted. Also, if you run this on your own data, note that you may need to wait a few minutes for results to come back.

In testing out various twitter clients, I wanted to get a feel for my personal usage (how much I've used each client), so I decided I'd write some code around it. To begin, here are the results:

web, 1770, 41.549%  Clipboard02
im, 1214, 28.498%
txt, 713, 16.737%
SnapFoo, 153, 3.592%
twigadge, 146, 3.427%
Twadget, 128, 3.005%
TwitterFox, 61, 1.432%
Snitter, 21, 0.493% 
Jott, 17, 0.399%
TwitBin, 16, 0.376%
twitterfeed, 7, 0.164%
Spaz, 6, 0.141%
Twitter Opera widget, 3, 0.070%
twhirl, 3, 0.070%
Twittearth, 2, 0.047%

I snagged an API code sample and fired up my trusty Visual Studio 2005. Thankfully (so I could step out of my box a bit), the code sample was in C# 3.5! So... I popped open my laptop and set out coding (finally, for the first time outside of dragging some controls around) in Visual Studio 2008.

As part of this, I wrote my first LINQ-to-XML query!

This code makes a request to twitter (you have to be authenticated first) and gets an anonymous type list called sc that has the key (the name of the source, as shown above) and the count from that page. After that I work some magic to aggregate them across all pages, though I'm investigating how to do the aggregation by first combining the XElement-s from each page (though that would take up a lot of memory).

url = "http://twitter.com/account/archive.xml?page=" + x.ToString();

WebRequest Request = HttpWebRequest.Create(url);
Request.Credentials = new NetworkCredential(userName, password);
WebResponse Response = Request.GetResponse();
Stream stream = Response.GetResponseStream();
TextReader reader = new StringReader(new StreamReader(stream).ReadToEnd());
XElement statuses = XElement.Load(reader);

// My first LINQ query!
var sourceNames = from source in statuses.Descendants("source")
                  group source by source.Value into sc
                  orderby sc.Count() descending
                  select new { sc.Key, MyCount = sc.Count() };

I also got to play around in WPF just a little. Nothing fancy at all, but it was nice to see the new IDE in action. It feels much more powerful.

I may play around with this some more, add graphing, toy around with it as a Silverlight 2 app. Or it might just sit there and do nothing ;-)

Posted on Tuesday, April 29, 2008 3:35 PM | Back to top


Comments on this post: Personal Twitter Client Counter

No comments posted yet.
Your comment:
 (will show your gravatar)
 


Copyright © Paul Whitaker | Powered by: GeeksWithBlogs.net | Join free