Save Your Journal
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:
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.
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;
}
Leave a comment