Posted By

iblis on 08/03/07


Tagged

snipplr backup rpc


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mabridge


Backup your snippets from snipplr.com


 / Published in: Perl
 

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

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Frontier::Client;
  4.  
  5. my $key = ''; # (your API key)
  6. my $user = ''; # used to skip others' snippets (fill with your user name)
  7.  
  8. my $session = Frontier::Client->new( url => 'http://snipplr.com/xml-rpc.php', debug => 0,);
  9.  
  10. $session->call('user.checkkey', $key)
  11. or die "Provided key has been refused!\n";
  12.  
  13. my @args = ($key, '');
  14. my $list = $session->call('snippet.list', @args);
  15.  
  16. my @snippets; # in case you need to process data afterwards (sort ...)
  17.  
  18. for (my $i=0 ; defined($_ = $list->[$i]) ; $i++) {
  19. my $data = $session->call('snippet.get', $_->{'id'});
  20. if ($data->{username} !~ /^$user$/) {next}; # skip favorites (back up just your snippets)
  21. $snippets[$i]=$data; # dump for post loop processing
  22. print "##### $data->{title}\n";
  23. print "##### $data->{comment}\n";
  24. print "##### $data->{language} $data->{tags}\n";
  25. print "##### $data->{source}\n";
  26. print "#####\n";
  27. print "#####\n";
  28. }
  29.  
  30. @snippets = sort {$a->{language} cmp $b->{language}} @snippets; # sort by language

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: tylerhall on August 3, 2007

You can also download a zip file backup of your snippets here: http://snipplr.com/zipbackup.php

Posted By: iblis on August 5, 2007

@tylerhall Thank you very much, I didn't notice the "download a ZIP file backup of all your snippets" link in the Settings tab. I fact, I was just going to improve my script to get exactly that: a dump in separate files. Still, the script can be useful to selectively back up scripts.

You need to login to post a comment.