Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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') ],
- ];
- };
Add Comment
Please, Sign In to add comment