Return to Snippet

Revision: 3503
at August 3, 2007 17:52 by iblis


Initial Code
#!/usr/bin/perl -w
use strict;
use Frontier::Client;

my $key = '';			# (your API key)
my $user = '';			# used to skip others' snippets (fill with your user name)

my $session = Frontier::Client->new( url => 'http://snipplr.com/xml-rpc.php', debug => 0,);

$session->call('user.checkkey', $key) 
	or die "Provided key has been refused!\n";

my @args = ($key, '');
my $list = $session->call('snippet.list', @args);

my @snippets;		# in case you need to process data afterwards (sort ...)

for (my $i=0 ; defined($_ = $list->[$i]) ; $i++) {
	my $data = $session->call('snippet.get', $_->{'id'});
	if ($data->{username} !~ /^$user$/) {next};	# skip favorites (back up just your snippets)
	$snippets[$i]=$data;				# dump for post loop processing
	print "##### $data->{title}\n";
	print "##### $data->{comment}\n";
	print "##### $data->{language} $data->{tags}\n";
	print "##### $data->{source}\n";
	print "#####\n";
	print "#####\n";
}

@snippets = sort {$a->{language} cmp $b->{language}} @snippets;		# sort by language

Initial URL

                                

Initial Description
Dumps your snippets (and possibly skips your favourites [British spelling]) to standard output. Requires Frontier::RPC2.

Initial Title
Backup your snippets from snipplr.com

Initial Tags
backup

Initial Language
Perl