Journal jcuervo's Journal: Still looking for that ThinkGeek fortune you added? 1
#!/usr/bin/perl -w
use Digest::MD5; use LWP::UserAgent;
$ua=LWP::UserAgent->new ({'agent' => 'ThinkGeekFortuneFinder/0.1'});
$|=!($almost_there=0);@sum=();
OUTER: while (1)
{
my ($response) = $ua->get('http://www.thinkgeek.com/fortune.shtml');
my ($quote, $sum, @quote);
die $response->status_line
if (! $response->is_success);
$almost_there = 0;
for (split /\n/, $response->content)
{
s/\r//g;
if ((!$almost_there)
&& $_ eq '<I>(refresh for another)</I><BR>')
{
$almost_there++;
}
elsif (($almost_there == 1 || $almost_there == 2) && $_ eq '')
{
$almost_there++;
}
elsif ($almost_there == 3)
{
last if ($_ eq '</p>');
s/<BR>/\n/g;
s/\</</g;
s/\>/>/g;
push @quote, $_;
}
}
pop @quote; # empty line
$quote = join "\n", @quote, "";
@quote = ();
$sum = Digest::MD5::md5_hex $quote;
for (@sum)
{
if ($_ eq $sum)
{
print STDERR $_ = "Already seen $sum";
sleep 1;
print "\b \b" x $_;
next OUTER;
}
}
push @sum, $sum;
print "--$sum\n$quote";
sleep 10;
}
use Digest::MD5; use LWP::UserAgent;
$ua=LWP::UserAgent->new ({'agent' => 'ThinkGeekFortuneFinder/0.1'});
$|=!($almost_there=0);@sum=();
OUTER: while (1)
{
my ($response) = $ua->get('http://www.thinkgeek.com/fortune.shtml');
my ($quote, $sum, @quote);
die $response->status_line
if (! $response->is_success);
$almost_there = 0;
for (split
{
s/\r//g;
if ((!$almost_there)
&& $_ eq '<I>(refresh for another)</I><BR>')
{
$almost_there++;
}
elsif (($almost_there == 1 || $almost_there == 2) && $_ eq '')
{
$almost_there++;
}
elsif ($almost_there == 3)
{
last if ($_ eq '</p>');
s/<BR>/\n/g;
s/\</</g;
s/\>/>/g;
push @quote, $_;
}
}
pop @quote; # empty line
$quote = join "\n", @quote, "";
@quote = ();
$sum = Digest::MD5::md5_hex $quote;
for (@sum)
{
if ($_ eq $sum)
{
print STDERR $_ = "Already seen $sum";
sleep 1;
print "\b \b" x $_;
next OUTER;
}
}
push @sum, $sum;
print "--$sum\n$quote";
sleep 10;
}
Whoops. (Score:1)