Wikipedia:Reference desk/Archives/Computing/Early/20050709 Dmcdevit

From Wikipedia, the free encyclopedia
This case has been resolved

Background info: there have been many VfD's that ended with a "transwiki" decision. Those articles that should now be deleted after they've been transwikied, but usually the transwikiers aren't the same as the admins, so after being transwikied, they are promptly forgotten (and not deleted). So, <technical help> I'm wondering if it would be possible to write something that would look at all the entries at WP:TL and put a link at the end of the line to a VfD page if one exists for that article. So for example the first entry would become:

Do you think this could be done? This is just a one-time thing to help clean out that log. </technical help> Of course this is not urgent, especially since it seems like you're probably busy. Thanks. --Dmcdevit July 9, 2005 02:06 (UTC)

Solution[edit]

I solved this with Perl using a regular expression to parse the list at WP:TL, then made an HTTP request to a VfD page for each article name from the list to create a list of articles that had VfD pages. Then I used another regular expression and a hash to tack on the VfD link suffix if the VfD page did exist. Triddle 02:19, July 10, 2005 (UTC)

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";
}