#!/usr/bin/perl use strict; use warnings; sub get_title { open( QUOTES, "-|", "wget -q 'http://www.quotationspage.com/random.php3' -O -" ) or die "Could not open wget: $!\n"; my $quote; while () { chomp; if (/^
.*//; $quote =~ s/.* (\S+) (\S+) (\S+) (\S+).$/$1 $2 $3 $4/; return ucfirst $quote; } sub get_band { open( BAND, "-|", "wget -q 'http://en.wikipedia.org/wiki/Special:Random' -O -" ) or die "Could not open wget: $!\n"; my $band; while () { if (/(.*?) - Wikipedia, the free encyclopedia<\/title>/) { $band = "$1"; last; } else { next } } close BAND; die "Could not get band name!\n" unless $band; return $band; } sub get_art { my $art; my $IN_BLOCK = 0; my $PHOTO_COUNT = 0; open( FLIKR, "-|", "wget -q 'http://www.flickr.com/explore/interesting/7days/' -O -" ) or die "Could not open wget: $!\n"; while (<FLIKR>) { if (not $IN_BLOCK) { if (/<table border="0" cellspacing="0" class="TwentyFour">/) { $IN_BLOCK = 1; } next; } else { if (/<td class="Photo"><span class="photo_container pc_m"><a href="\/photos\/\S+" title=".*?"><img src="(\S+)"/) { if (++$PHOTO_COUNT == 3) { $art = "$1"; last; } else { next } } } } close FLIKR; die "Could not get art!\n" unless $art; return $art; } printf "Band: %s\nAlbum: %s\nArt: %s\n", get_band(), get_title(), get_art();