aboutsummaryrefslogtreecommitdiff
path: root/contrib/pinboard.pl
blob: 06fc87a4c7f8ab53499e5ed8525e47d8fcbb7058 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env perl

use strict;
use LWP::UserAgent;
use URI::Escape;


######## User settings #############
# Daemonise the bookmarking process
# Use this only if you are sure things
# are working as expected. Needs the
# Proc::Daemon Perl module
# set to '0' if not needed
my $daemon = 1;


# Change the tag value to what you
# want the bookmarks to be tagged as
# at Pinboard
my $tag='newsbeuter';

# Get yours at https://pinboard.in/settings/password
# Of the form 'username:alphanumeric'
my $API_token='***REPLACE***';
######## No user settings below this line #############


# $ARGV[0] is the URL of the article
# $ARGV[1] is the title of the article
# $ARGV[2] is the description of the article
# $ARGV[3] is the feed title (not used by Pinboard)

if ($daemon) {
    eval {
        require Proc::Daemon;
        Proc::Damoen->import();
    };
    if($@) {
        warn();
    } else {
        Proc::Daemon::Init();
    }
}

my $API_URL='https://api.pinboard.in/v1/posts/add?';
my $bkmrk_url='';

# Get redirected URL's permalink
my $ua = LWP::UserAgent->new(
    requests_redirectable => [],
);

my $res = $ua->get($ARGV[0]);

if ($res->status_line == 301) {
	$bkmrk_url = $res->header( 'location');
} else {
    $bkmrk_url = $ARGV[0];
}

my $safe_bkmrk_url = uri_escape($bkmrk_url);
my $safe_title = uri_escape($ARGV[1]);
my $safe_description = uri_escape($ARGV[2]);

my $pinboard_url = $API_URL . "auth_token=$API_token&url=$safe_bkmrk_url&tags=$tag&shared=no&toread=yes&description=$safe_title&extended=$safe_description";
my $content = `curl -s \"$pinboard_url\"`;

if ($content =~ m!<result code="done" />!) {
#    print "Added to Pinboard\n";
} else {
    print STDERR " Opps $content" if $content;
    print STDERR " Bookmark not added! URL: $pinboard_url";
}