Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created March 19, 2010 22:50
Show Gist options
  • Save miyagawa/338284 to your computer and use it in GitHub Desktop.
Save miyagawa/338284 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# TWITTER_USERNAME=xxx TWITTER_PASSWORD=xxx plackup -s Twiggy tweet_displayer.pl
use 5.010;
use AnyEvent::Twitter::Stream;
use Markapl;
use autobox::Core;
use autobox::Encode;
my $buf = [];
# NOTE: $stream should live outside this PSGI file scope
# Change state to our if you're using perl 5.8
state $stream = AnyEvent::Twitter::Stream->new(
username => $ENV{TWITTER_USERNAME},
password => $ENV{TWITTER_PASSWORD},
method => 'sample',
on_tweet => sub {
my $tweet = shift;
$buf->unshift($tweet);
$buf = $buf->slice(0..9) if $buf->size >= 10;
},
);
sub {
my $mp = html { body { ul { $buf->map(sub { li { $_->{text} } }) } } };
return [
200,
[ 'Content-Type', 'text/html; charset=utf-8' ],
[ $mp->()->encode('utf8') ],
];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment