Sure. The script is in /web/perl/NX/scripts/twittersync.pl
It doesn't have any comments though, so I am not sure how useful it would be. It's also setup to insert the results into the Postgres database on nullray and then calls other scripts to actually post to nullray.
Basically you use LWP to grab the RSS feed (LWP is the standard way to grab stuff that can be addressed with a URL):
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
$ua->evn_proxy;
my $url = "
http://feedurl...whatever";
my $response = $ua->get($url);
die $response->status_line, " on $url" unless $response->us_success;
my $raw_rss = $response->decode_content;
Now you have the raw RSS (XML) and you need to parse it. There are lots of ways to do this, but the simplest (as long as you don't care about XSD verification or anything like that) is XML::Simple
use XML::Simple qw( XMLin );
my $feed = XMLin($raw_rss);
This creates a "hash of hashes" that represents the hierarchical nature of the XML. If you want to see what the results look like in Perl terms, use Data::Dumper (YAML is also a handy way to look at this kind of data, but it is cross-language and not Perl specific).
use Data::Dumper qw( Dumper );
print Dumper($feed);
But anyhow, to iterate over each item in the RSS feed, this is what you do:
my @items = ref $items eq 'ARRAY' ? @$items : ($items) ;
foreach my $item (@items)
{
my $link = $item->{link};
my $description = $item->{description};
my $pub_date = $item->{pubDate};
# ...
# do something with these values
}
You need the ?: operator in the assignment of @items, because if there is only one item it will be stored as a scalar instead of a list (this is a limitation of XML::Simple, it can't tell the difference between something that should be a single XML element and something that is a list of just one XML element).
The script that posts to lj is /web/perl/NX/scripts/ljsync.pl and also devoid of many comments. It's also probably not directly useful since it grabs items from the database. Basically I wrote my own LJ client code NX::LiveJournal (lives in /web/perl/NX/LiveJournal), because I wasn't happy with the ones that are found on CPAN. It's actually quite good (I was at one point thinking about submitting it to CPAN) but the interface is not documented at all (of course! oh dear).
use NX::LiveJournal::Client;
my $lj = new NX::LiveJournal::Client(
username => 'blah',
password => 'secret',
server => 'www.livejournal.com',
mode => 'cookie', # should be 'challenge' for deadjournal
);
die "error connecting to www.livejournal.com $NX::LiveJournal::Client::error" unless defined $lj;
Determining the mode is a process of trial and error. 'cookie' is better (because it doesn't mean 2 HTTP request for every 1 real request), but the DJ server is older and only works with 'challenge'.
$event = $lj->create;
$event->eventtime('2008-09-26 04:30:00');
$event->subject('subject');
$event->event('actual message text');
$event->settags(qw( funny story test ));
#$event->setprop(opt_preformatted => 1); # if you don't want LJ to add
tags and stuff
$event->update;
the NX::LiveJournal stuff uses mostly the terminology used in the LJ XML-RPC API, and some of it (to me at least) seems a bit odd. It's pretty complete, including all the stuff that is in the LJ API, even stuff that I don't really use. It isn't well documented, but if you use it in conjunction with the LJ API documentation it might make sense.
The other option is using LJ::Simple (which is installed on nullray). I think that it has serious problems though. Net::LiveJournal is a joke so don't even go there.
Incidentally, documentation for everything that is installed in the nullray perl can be found on this page:
www.wdlabs.com/doc
click on "Perl 5.10.0 (/web/bin/perl)" (it requires your nullray username and password).
If you are interested in working on any of this I'd be happy to give you access to the subversion repository. :)