Wiki143:WikiProject help desk/20050709 Dmcdevit.pl
Jump to navigation
Jump to search
Generates a list of all the articles from the rendered VfD page
#!/usr/bin/perl -w
use strict;
while (<>) {
next unless /^\*(<s>)?\[\[(.+?)\]\]/;
print $2, "\n";
}
Checks to see if a VfD page exists for a list of articles
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use URI::Escape;
my $pause = 1; #seconds between http fetches
$| = 1;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
while(<>) {
chomp;
if (check('Wikipedia:Votes_for_deletion/' . uri_escape($_))) {
print $_, "\n";
}
sleep($pause);
}
#returns 1 if a wikipedia article exists at that name, 0 otherwise
sub check {
my $name = shift;
my $uri = 'http://en.wikipedia.org/wiki/' . $name;
my $text;
while(1) {
my $resp = $ua->get($uri);
if ($resp->is_success) {
$text = $resp->content;
last;
} else {
print STDERR "WARNING: $uri failed: ";
print STDERR $resp->status_line, "\n";
}
sleep($pause);
}
return 1 if index($text, '<b>Wikipedia does not have an article with this exact name.</b>') == -1;
return 0;
}
Adds the links to the wikitext of VfD if it is in the list specified
#!/usr/bin/perl -w
use strict;
my %has_vfd;
my $file = shift(@ARGV) or die "must specify file name";
open(FILE, $file) or die "could not open $file: $!";
while(<FILE>) {
chomp;
$has_vfd{$_} = 1;
}
close(FILE);
while(<>) {
chomp;
if (/^\*(<s>)?\[\[(.+?)\]\]/ && defined($has_vfd{$2})) {
print $_, " ([[Wikipedia:Votes for deletion/$2|VfD]])";
} else {
print;
}
print "\n";
}