#!/usr/bin/perl use lib "../lib"; # Load MySpace blog RSS and display use CGI qw(param); use CGI::Carp qw(fatalsToBrowser); use XML::Simple; #use XML::Parser; use XML::SAX; use IO::Socket::INET; use LWP::Protocol::http; require LWP::UserAgent; use Data::Dumper; use strict; my $view = param('view'); # 1) download Feed my $url = "http://blog.myspace.com/blog/rss.cfm?friendID=67670064"; $url = "http://blogs.myspace.com/Modules/BlogV2/Pages/RssFeed.aspx?friendID=67670064"; my $rerror = sub { my $txt = join("",@_); die "HttpViewer Error: $txt\n" }; my $useragent = LWP::UserAgent->new or &$rerror("Could not create User-Agent: $!"); #$useragent->agent("HttpViewer/$VERSION/".$useragent->agent) $useragent->agent("kyuguild.com RSS reader") #Mozilla Perlding IE") or &$rerror("Could not set User-Agent name: $!"); $useragent->timeout(120) or &$rerror("Failed to set timeout to 120: $!"); my $request = HTTP::Request->new('GET', "$url") || die "Could not create request: $!"; my $response = $useragent->simple_request($request); $response = $response->as_string(); $response =~ s/^.+?\n\n//sg; print "Content-type: text/html\n\n"; print qq( KYU Blog/News

KYU Blog/News

These messages are derived from our mySpace. On ourSpace you can respond to our messages as well...

); print qq(); # 2) Parse my $feed = XMLin($response); my @items = @{ $feed->{'channel'}->{'item'} }; my $dot = "."; if ($view eq "short") { # JavaScript righthand shortcuts print qq(
); # 2 items my $br = ""; foreach my $item ($items[0],$items[1]) { # color:#A71A1F; # FRI.JUN.15.2007@20:00 # Mon, 16 Apr 2007 05:22:00 PST: $item->{pubDate} =~ /^(\w+), (\d+) (\w+) (\d\d\d\d) (\d\d:\d\d):/; my $date = uc($1).$dot.uc($3)."$dot$2$dot$4\@$5"; my $title = uc($item->{title}); my $text = expand($item->{description}); print qq($br$date
$title

\n); $br = "
"; } print qq(
); } else { foreach my $item (@items) { # color:#A71A1F; # FRI.JUN.15.2007@20:00 # Mon, 16 Apr 2007 05:22:00 PST: $item->{pubDate} =~ /^(\w+), (\d+) (\w+) (\d\d\d\d) (\d\d:\d\d):/; my $date = uc($1).$dot.uc($3)."$dot$2$dot$4\@$5"; my $title = uc($item->{title}); my $text = expand($item->{description}); print qq(

$title


$date: $text
View or add response (\@mySpace)

); } =pod { 'link' => 'http://blog.myspace.com/index.cfm?fuseaction=blog.view&friendID=67670064&blogID=256301100', 'description' => 'Hi ya\'ll.We did it, we won the parel van de betuwe.Thanks everybody for showing up and giving us good lovin\'.So now we can play on appelpopGREAT!!!!see you there!...', 'title' => 'kyu wins parel van de betuwe', 'pubDate' => 'Sun, 22 Apr 2007 03:32:00 PST', } =cut #print "\n\n
";
#print Dumper($feed);
#print "
\n"; } print "\n"; sub expand { =head2 expand my $html = expand($text); Filterd de gegeven $text zo dat emailadressen en URLs geexpandeerd worden tot HTML hyperlinks. Ook worden speciale karakters naar HTML geconverteerd. Antispam: Voorlopig doen we het met @ IPV @ =cut my ($text) = @_; my $email = '[\w\.\{\},\[\]\~\#\$\^\*]+'; #my $url = '[\w\.\{\},\[\]\~\#\$\^\*\\\/\;\:]+'; #my $test; # Jan 2007 we willen
DIT
wel in tact houden .... my @pre; while ($text =~ //si) { my $i = scalar(@pre); $text =~ s/()/\$pre[$i]/si; $pre[$i] = $1; $pre[$i] =~ s/\n/ \n/g; #$test .= ""; } $text =~ s/
/
/gi; $text =~ s/

/

/gi; $text =~ s/<\/p>/ <\/p> /gi; $text =~ s/ *[\r\n]+ */ \n /gi; for (my $i = 0; $i < @pre; $i++) { $text =~ s/\$pre\[$i\]/ $pre[$i] /; } my @words = split (/ /,$text); my $word; foreach $word (@words) { unless ($word =~ /[<>]/) { if ($word =~ /^(\(?\n?)http:\/\//i) { my $a = $1; my $b = ""; if ($word =~ /(\.|,|\))$/) { $b = $1; } $word =~ s/(?:^\(|\.$|,$|\)$|\n)//g; $word = "$a".substr(lc($word),7)."$b"; } elsif ($word =~ /^(\(?\n?)www\..+\.(?:nl|com|org|net|edu|be)(\.|,|\))?$/i) { my ($a,$b) = ($1,$2); $word =~ s/(?:^\(|\.$|,$|\)$|\n)//g; $word = "$a".lc($word)."$b"; } elsif ($word =~ /^(.*?)($email\@$email\.$email)(.*?)$/s){ my ($a,$b,$c) = ($1,$2,$3); unless ($c) { unless ($b) { $b = $a; $a = ""; } } while ($b =~ s/(\.|,)$//) { $c = $1 . $c; } #$word =~ s/^\(*//g; $word ="$a$b$c"; } #elsif ($word =~ /^(\(*).*\@.*\..*/s){ # my $a = $1; # my $b = ""; # while ($word =~ s/(\.|,|\))$//) { # $b = $1 . $b; # } # $word =~ s/^\(*//g; # $word ="$a$word$b"; # } } } $text = join(" ",@words); $text =~ s/\@/@/g; #$text =~ s/
/
/g; return $text;#.$test; }