Created
June 23, 2012 18:17
-
-
Save renestein/2979279 to your computer and use it in GitHub Desktop.
Simple twitter account checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Reactive.Linq; | |
using System.Text; | |
using System.Xml.Linq; | |
namespace TwitterSearcher | |
{ | |
class Program | |
{ | |
public const int DEFAULT_MINUTES = 1; | |
public const string URL = "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=vodafone_cz"; | |
public static readonly XNamespace TWIITER_XML_NAMESPACE = "http://api.twitter.com"; | |
static void Main(string[] args) | |
{ | |
var wc = new WebClient(); | |
var timer = Observable.Timer(TimeSpan.FromMinutes(DEFAULT_MINUTES), TimeSpan.FromMinutes(DEFAULT_MINUTES)) | |
.Do(_ => wc.DownloadStringAsync(new Uri(URL))); | |
var data = Observable.FromEventPattern( | |
handler => wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(handler), | |
handler => wc.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(handler)) | |
.Retry() | |
.Select(ep => ((DownloadStringCompletedEventArgs) ep.EventArgs).Result) | |
.Select(twitterXml => (string) XElement.Parse(twitterXml).Descendants("item").First().Element("description")) | |
.DistinctUntilChanged(s => s, StringComparer.InvariantCultureIgnoreCase) | |
.Finally(wc.Dispose); | |
var timerSubscription = timer.Subscribe(Console.WriteLine); | |
var dataSubscription = data.Subscribe(Console.WriteLine); | |
Console.ReadLine(); | |
timerSubscription.Dispose(); | |
dataSubscription.Dispose(); | |
} | |
} | |
} |
@
Good
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
helli