Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
Created July 6, 2012 08:15
Show Gist options
  • Save jgrahamc/3058887 to your computer and use it in GitHub Desktop.
Save jgrahamc/3058887 to your computer and use it in GitHub Desktop.
Alan Turing script
use strict;
use warnings;
use WWW::Mechanize;
use DB_File;
my %signed;
tie %signed, "DB_File", "signed", O_RDWR|O_CREAT,
0666, $DB_HASH or die "Failed to open signed\n";
my $m = WWW::Mechanize->new();
my $p = 'http://petitions.number10.gov.uk/turing/?showall=1';
$m->get($p);
if ( !$m->success() ) {
die "Failed to download name list\n";
}
# This is brittle and would be better done with an HTML parser
my $h = $m->content();
while ( $h =~ /<li>([^<]+)<\/li>/g ) {
my $n = $1;
if ( !defined( $signed{$n} ) ) {
test($n);
$signed{$n} = 1;
}
}
untie %signed;
sub test
{
my ( $n ) = @_;
print "$n\n";
my $g = WWW::Mechanize->new();
$g->get('http://en.wikipedia.org/');
if ( !$g->success() ) {
die "Failed to access Wikipedia\n";
}
$g->field('search', $n);
$g->click('go');
if ( !$g->success() ) {
die "Wikipedia search failed\n";
}
my $t = $g->title();
if ( $t =~ /(Search Results|not found)/i ) {
return;
}
foreach my $a (split(' ', $n)) {
if ( $t !~ /$a/i ) {
return;
}
}
my $b = $g->text();
if ( $b =~ /British|English|Scottish|Welsh|Irish/i ) {
print "Potential VIP $n: ", $g->uri(), "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment