Skip to content

Instantly share code, notes, and snippets.

@mfakane
Created May 19, 2012 13:13
Show Gist options
  • Save mfakane/2730817 to your computer and use it in GitHub Desktop.
Save mfakane/2730817 to your computer and use it in GitHub Desktop.
ふぁぼふぁぼ
using System;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Codeplex.OAuth;
using Linearstar.Psycho;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var auth = new OAuthAuthorizer("consumer key", "consumer secret");
var token = auth.GetRequestToken("https://twitter.com/oauth/request_token")
.Select(_ => new
{
Url = auth.BuildAuthorizeUrl("https://twitter.com/oauth/authorize", _.Token),
_.Token,
})
.Do(_ => Process.Start(_.Url))
.Zip(Observable.Defer(() => Observable.Return(Console.ReadLine())), Tuple.Create)
.SelectMany(_ => auth.GetAccessToken("https://twitter.com/oauth/access_token", _.Item1.Token, _.Item2))
.Single();
using (var ctx = new TwitterContext(auth, token.Token))
Observable.Defer(() =>
{
var maxId = (ulong?)null;
return Observable.Range(0, 20)
.Select(r => ctx.Statuses.UserTimeline(screenName: "karno", count: 50, maxId: maxId).Result)
.Do(l => maxId = l.Last().Id)
.SelectMany(l => l);
})
.Where(_ => !_.Favorited && _.RetweetedStatus == null)
.Select(_ => _.Id)
.Distinct()
.Subscribe(_ => Task.Run(async () =>
{
try
{
var s = await ctx.Favorites.Create(_).ToObservable().Retry(3).ToTask();
Console.WriteLine(s.User.ScreenName + ": " + s.Text);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment