Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
User Journal

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/\&lt;/</g;
                        s/\&gt;/>/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;
}
This discussion has been archived. No new comments can be posted.

Still looking for that ThinkGeek fortune you added?

Comments Filter:

Waste not, get your budget cut next year.

Working...