Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Tuesday June 15, 2004
04:36 PM

Save Your Journal

[ #19275 ]

I just read about everybody's favorite blogger -- who shall remain nameless, because I don't wish to discuss him -- shutting down a popular blogging site he was running, without notice. One person commented thusly:

There you go boys and girls: the number one reason why you don't want to go with a hosted solution, and if you do, backup. Frequently. No matter how nice or cuddly or professional the host -- back your material up at least weekly. Never give anyone control over what happens to your writing. Never.

Sound advice, that.

Also, we are today going to be shutting down use.perl.org for some major code upgrade, which will also mean data upgrades. And something bad things happen.

So I wrote this little script, to save all my use.perl.org journals (using the SOAP interface). Share and enjoy. Only TorgoX, for now, would need to change $max.

Ideally there should be a good way to not get all the entries in the first run, but only the necessary ones. Maybe the next time I modify the SOAP interface, I'll do that. Maybe an additional parameter for get_entry, to note the last entry you don't want.

Also, if you modify a journal entry, this won't help you, as there's no last modified time or anything of the sort. Just rm your local file.

#!/usr/bin/perl
use warnings;
use strict;
 
$ENV{TZ} = 'GMT';
 
use Data::Dumper;
use Date::Parse;
use File::Path;
use File::Spec::Functions;
use SOAP::Lite;
 
my $host        = 'use.perl.org';
my $uri         = "http://$host/Slash/Journal/SOAP";
my $proxy       = "http://$host/journal.pl";
my $uid         = 1;
my $backup      = catdir($ENV{HOME}, 'Documents', 'journal', $host);
my $max         = 1000;
 
mkpath($backup);
 
my $journal = SOAP::Lite->uri($uri)->proxy($proxy);
my $recents = $journal->get_entries($uid, $max)->result;
 
for my $recent (@$recents) {
    my $id = $recent->{id};
    my $file = catfile($backup, $id);
    next if -e $file;
    my $entry = $journal->get_entry($id)->result;
 
    open my $fh, '>', $file or die "Can't open $file: $!";
    print $fh Dumper $entry;
    close $fh;
 
    my $time = str2time($entry->{date});
    utime $time, $time, $file;
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.