Backup your snippets from snipplr.com


/ Published in: Perl
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.