Created
April 28, 2011 17:01
-
-
Save leedo/946757 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 strict; | |
use warnings; | |
use Redis; | |
my $password = ''; | |
my $host = ''; | |
sub random_image { | |
my $redis = Redis->new(server => $host); | |
$redis->auth($password); | |
my $key = $redis->randomkey; | |
my $len = $redis->llen($key); | |
my $index = int(rand($len)) - 1; | |
return $redis->lindex($key, $index); | |
} | |
sub { | |
my $image = random_image; | |
my $body = "<a href='/'><img src='$image'></a>"; | |
[200, ['Content-Type' => 'text/html', 'Content-Length' => length $body], [$body]] | |
} |
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
#!/usr/bin/env perl | |
use ExtUtils::MakeMaker; | |
WriteMakefile( | |
PREREQ_PM => {'AnyEvent::Feed' => '0.3'}, | |
PREREQ_PM => {'AnyEvent::Redis' => '0.23'}, | |
PREREQ_PM => {'Redis' => '1.904'}, | |
); |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Feed; | |
use AnyEvent::Redis; | |
my $password = ''; | |
my $host = ''; | |
my $port = ''; | |
my @feeds; | |
my $redis = AnyEvent::Redis->new( | |
host => $host, | |
port => $port, | |
); | |
my $img_re = qr{https?://[^\s]+\.(?:gif|png|jpe?g)}i; | |
my $cv = AE::cv; | |
sub add_feed { | |
my $url = shift; | |
my $feed = AnyEvent::Feed->new(url => $url); | |
$cv->begin; | |
$feed->fetch(sub { | |
my ($reader, $new, $feed, $error) = @_; | |
my @images = map {($_->content->body =~ /($img_re)/g)} $feed->entries; | |
$redis->del($url, sub {}); | |
for my $image (@images) { | |
$cv->begin; | |
$redis->lpush($url, $image, sub {$cv->end}); | |
} | |
$cv->end; | |
}); | |
push @feeds, $feed; | |
} | |
$redis->auth($password, sub {}); | |
add_feed 'http://cutegirlsbeingcute.tumblr.com/rss'; | |
add_feed 'http://getoutoftherecat.tumblr.com/rss'; | |
add_feed 'http://thisiswhyyourefat.tumblr.com/rss'; | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment