-
-
Save sekimura/339019 to your computer and use it in GitHub Desktop.
fixed name of this script itself and added "feature" pragma
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
#!/usr/bin/perl | |
# TWITTER_USERNAME=xxx TWITTER_PASSWORD=xxx plackup -s Twiggy twitter_displayer.pl | |
use AnyEvent::Twitter::Stream; | |
use Markapl; | |
use autobox::Core; | |
use autobox::Encode; | |
use feature qw(state); | |
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; | |
return unless $tweet->{user}; | |
$buf->unshift($tweet); | |
$buf = $buf->slice(0..9) if $buf->size >= 10; | |
}, | |
); | |
sub { | |
my $mp = html { | |
body { | |
ul { $buf->map(sub { | |
li { | |
b{ $_->{user}->{screen_name} }; | |
': ' . $_->{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