Created
April 27, 2011 16:32
-
-
Save leedo/944614 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use Plack::Builder; | |
use AnyEvent::Feed; | |
use POSIX qw/ceil/; | |
my @image_urls; | |
my $img_re = qr{https?://[^\s]+\.(?:gif|png|jpe?g)}i; | |
my $feed = AnyEvent::Feed->new( | |
url => 'http://cutegirlsbeingcute.tumblr.com/rss', | |
interval => 60 * 60, # every hour | |
on_fetch => sub { | |
my ($reader, $new, $feed, $error) = @_; | |
return unless @$new; | |
@image_urls = map {($_->content->body =~ /($img_re)/g)} $feed->entries; | |
}, | |
); | |
builder { | |
mount "/" => sub { | |
my $env = shift; | |
my $image = $image_urls[ceil(rand($#image_urls))]; | |
return [301, [Location => $image], []]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment