All pastes #915192 Raw Edit

Someone

public text v1 · immutable
#915192 ·published 2008-02-23 16:43 UTC
rendered paste body
#!/usr/bin/perl5 
 
BEGIN {
    my $homedir = (getpwuid($>))[7];
    my $n_inc = scalar @INC;
    for (my $i = 0; $i < $n_inc; $i++) {
        if (-d $homedir . '/perl' . $INC[$i]) {
	    unshift(@INC,$homedir . '/perl' . @INC[$i]);
	    $n_inc++;
	    $i++;
	}
    }
}	

use strict;
use HTTP::Date;
use LWP::Simple;
use XML::RSS;
 
    my $p1 = get("http://www.gaiaonline.com/forum/c-t-tech-talk/what-i-have-learned-from-c-t/t.804547_1/");
    $p1=~m:\Q<a href="/forum/c-t-tech-talk/what-i-have-learned-from-c-t/t.804547_\E(\d+)\Q/"  title="last page" class="page_jump" \E>:s;
    my $lpn = $1;
    $_ = get("http://www.gaiaonline.com/forum/c-t-tech-talk/what-i-have-learned-from-c-t/t.804547_$lpn/");
    if(!$_){
        print "Error getting page. Exiting.\n";
        exit(1);
    }
    print "Getting posts from $lpn\n";
 
    my @posts = ();
    while(/\Q<a href="\E\/forum.*?name="(\d*)".*?created on (.*?)">.*?\Q<span class="user_name"\E.*?>(.*?)<\/span>.*?\Q<!-- START forum.posts.messagecontent\E.*?-->(.*?)<!--/gs){
        my %tempHash = ('id'=>$1, 'date'=>$2, 'name'=>$3, 'body'=>$4);
        $tempHash{'body'}=~s/\Q<td class="\E[a-z]*_[ac].*?<\/td>//ig;
       $tempHash{'body'}=~s/\Q<td class="\E[a-z]*_b[13].*?<\/td>//ig;
        push(@posts, {%tempHash});
    }
    
    my $rss = new XML::RSS(version=>'1.0');
    $rss->channel(title=>"WIHL", link=>"http://www.gaiaonline.com/forum/c-t-tech-talk/what-i-have-learned-from-c-t/t.804547_$lpn/");
 
    for my $i ( 0 .. $#posts ) {
        my $body = $posts[$i]{'body'};
        my $id = $posts[$i]{'id'};
        my $name = $posts[$i]{'name'};
        
        $rss->add_item(title=>"Post by $name", link=>"http://www.gaiaonline.com/forum/c-t-tech-talk/what-i-have-learned-from-c-t/t.804547_$lpn/", 
                       description=>"$body", dc=>{creator=>"$name"});
                       
        print $rss->as_string;
        $rss->save("wihl.rdf"); 
    }