Encyclopedia > Simon J Kissane yrget perl script

  Article Content

User:SJK/yrget perl script

Redirected from Simon J Kissane/yrget perl script

< User:SJK

#!/usr/local/bin/perl -w
use strict;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

# Set attributes on UA
$ua->timeout(30);
$ua->agent("SJK downloading Year in Review: " . $ua->agent);
$ua->env_proxy ();

# fetch each article
open ENTRIES, "<ENTRIES"
  or die "can't open ENTRIES file: $!";

while (<ENTRIES>) {
  chomp;
     
     my $url = "http://www.wikipedia.com/wiki.cgi?action=history&id=$_";

     print "Getting $url...
";
     my $request = HTTP::Request->new('GET', $url);
     my $response = $ua->request($request);
     if ($response->is_error) {
	 die $response->status_line . " 
";
     }
 
     my $maxrev = 0;
     my @lines = split(/
/,$response->content);

     for my $line (@lines) {
	 if ($line =~ [[Simon_J_Kissane/Revision|/Revision]] ([0-9]*): <a class=encyclopedia href=/so) {
	     if ($1 > $maxrev) { $maxrev = $1; };
	 }
     }
    
     $url = "http://www.wikipedia.com/wiki.cgi?action=edit&revision=$maxrev&id=$_";

     print "Getting $url...
";
     $request = HTTP::Request->new('GET', $url);
     $response = $ua->request($request);
     if ($response->is_error) {
	 die $response->status_line . " 
";
     }
 
    
     open DATA, ">data/$_"
	 or die "Can't open data/$_: $!";
     if ($response->content =~ /<textarea[^>]*>(.*)</textarea>/s) {
	 my $out = "#YEAR [[$_]] REV=$maxrev
" . $1;
	 $out =~ s/'/'/g;
	 print DATA $out;
     }
     close DATA;
 }

See also : Simon J Kissane



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
U.S. presidential election, 1804

... 1812, 1816 Source: U.S. Office of the Federal Register (http://www.archives.gov/federal_register/electoral_college/scores.html#1804) (Larger version) See also: ...

 
 
 
This page was created in 28.4 ms