Created
May 15, 2013 05:45
-
-
Save jadeallenx/5581871 to your computer and use it in GitHub Desktop.
This is my silly little importer for clipboard.com exports. You will need a recent Perl ( >= 5.14 ) and updated HTTP::Tiny, IO::Socket::SSL and Path::Tiny CPAN modules. Get your clipboard.com export file, unzip it somewhere convenient (mkdir /tmp/cbexport; unzip {{UUID}}.zip; ./kippt-import.pl)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl -C | |
# My ghetto clipboard.com clip importer for kippt. | |
# | |
# cpanm HTTP::Tiny IO::Socket::SSL Path::Tiny | |
use 5.014; | |
use Path::Tiny; | |
use HTTP::Tiny; | |
use JSON::PP; | |
use Encode qw(decode encode); | |
our $VERSION = 0.01; | |
die "No kippt username\n" unless defined $ENV{KIPPT_USERNAME}; | |
die "No kippt API key\n" unless defined $ENV{KIPPT_API_KEY}; | |
my %headers = ( | |
'X-Kippt-Username' => $ENV{KIPPT_USERNAME}, | |
'X-Kippt-API-Token' => $ENV{KIPPT_API_KEY}, | |
'Content-Type' => 'application/json', | |
'X-Kippt-Client' => "kippt_import.pl:$VERSION,mrallen1\@yahoo.com", | |
); | |
my $base_url = 'https://kippt.com/api'; | |
my $json = JSON::PP->new; | |
my $ua = HTTP::Tiny->new( | |
default_headers => \%headers, | |
); | |
my $clips_iter = path("./clips")->iterator( { recurse => 1 } ); | |
my $clips; | |
while ( my $path = $clips_iter->() ) { | |
if ( $path->is_file && $path =~ /data\.json/ ) { | |
my $data = $json->utf8->decode(encode('utf8', $path->slurp_raw)); | |
my $out = { | |
url => $data->{url}, | |
title => decode('utf8', $data->{title}), | |
}; | |
next unless defined $out->{url}; | |
my $content = $json->encode($out); | |
my $r = $ua->request('POST', "$base_url/clips", { content => $content }); | |
if ( $r->{success} ) { | |
say "Saved $out->{title} (id: $data->{id})"; | |
$path->parent->child("processed")->touch(); | |
} | |
else { | |
die "Failed to store $data->{id}: $r->{status}: $r->{content}\n"; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment