Mirroring blogs from Drupal to LiveJournal

Submitted by Falken on

Well, that was easy :-) Much, much easier than the same thing from SlashCode, which was the expected-but-pleasing-anyway outcome.
Everything that I post into my On:Blog ends up on LJ too.

The code is below, in case anyone else finds it useful.
You'll need the LJ::Simple perl module in addition to the standard LWP module.


use LWP;
use LJ::Simple;

my $browser = LWP::UserAgent->new;

$url= "http://www.your.site/node/feed";

$response = $browser->get( $url );
die "$url error: ", $response->status_line
unless $response->is_success;

open (FILE, "){
$last=$last.$_;
}
close FILE;

if ($last eq $response->content){
print "same\n";
exit;
}else{
open (FILE, ">last-sum");
print FILE $response->content;
close FILE;
}

@rows=split(/\n/,$response->content);

$title="";
$mess="";
$inItem=0;
$inDesc=0;
$done=0;

foreach (@rows){
#print "considering $_ \n";
if ($_=~/item/){$item=1;}
if ($item eq 1 && $_=~/title/){$title=$_;$mess="";}
if ($item eq 1 && $_=~/description/){$inDesc=1;$mess="$mess$_";}
elsif ($item eq 1 && $inDesc eq 1 ){$mess="$mess$_";}
if ( ($inDesc eq 1) && ($_=~/\/description/) ){$inDesc="0";}

if (!($title eq "") && !($mess eq "") && ($inDesc eq 0)){
#print "title=$title\nmsg=$mess\n";
if ($mess=~/class="poll"/){

}
else {
$title=~/>(.*)(.*)/g;
$mess="(mirrored from my real blog)$mess";
print "title=$title\nmsg=$mess\n";
LJ::Simple::QuickPost(
user => "your-lj-user",
pass => "your-lj-password",
subject => $title,
entry => $mess,
protect => 'friends'
) || die "$0: Failed to post entry: $LJ::Simple::error\n";
exit;
}
}
}

Submitted by courtnee (not verified) on Tue, 04/11/2006 - 21:22

Permalink

Hey there. I fear this may be terribly rude of me, but you never know until you ask right? I'm in the third solid day of mucking around with Drupal, trying to decide if a CMS is really my style, and one of the main things I wish to do is prop my journal entries to my LJ. Would you consider assisting me in getting this set up on my site? I've got the perl modules installed, but am failing to see how I plug the code you have posted here into Drupal? Thanks a lot for your consideration.. -nee

Submitted by Falken on Thu, 05/25/2006 - 18:52

In reply to by courtnee (not verified)

Permalink

Take the code and modify the urls as needed at the top, and add your LJ details at the bottom.

Then just make sure the code runs every few hours.

Tom
PS Sorry for delay in replying !