This code basically grabs the
Newest Nodes XML, grabs each node and mails it...
#!/usr/bin/perl -w
use strict;
use XML::Parser;
use LWP::Simple;
use MIME::Lite;
my $parser = new XML::Parser ( Handlers => { Start => \&hdl_start, Cha
+r => \&hdl_char});
my $id = undef;
my %Nodes = ();
my $type = undef;
my $xml_stream = get("http://perlmonks.com/index.pl?node=newest+nodes+
+xml+generator");
$parser->parse($xml_stream);
foreach my $key (keys %Nodes)
{ my $page = get("http://perlmonks.com/index.pl?node_id=$key");
my $msg = MIME::Lite->new(
From =>'someone@somewhere.com',
To =>'someone@someplace.else.com',
Subject => "Perlmonks Node $Nodes{$key}",
Data => "Perlmonks Newest Nodes"
);
$msg->attach(Type =>'text/html',
Data =>$page);
$msg->send;
print "Sending part $Nodes{$key}\n";
}
sub hdl_start{
my ($p, $elt, %atts) = @_;
$type = $elt;
if ($type eq "NODE") { $id = $atts{node_id}; }
}
sub hdl_char {
my ($p, $str) = @_;
$str =~ s/\n//g;
if ($type eq "NODE" && $str) {
#print $id," => ",$str,"\n";
$Nodes{$id} = $str; }
}
Todo:
Ofcourse this could be used as base for an
NNTP link...
Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.