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
Johann Karl Friedrich Rosenkranz

... Heidelberg, devoting himself mainly to the doctrines of Hegel and Schleiermacher. After holding the chair of philosophy at Halle for two years, he became, in 1833, ...

 
 
 
This page was created in 27.4 ms