Last active
December 11, 2015 07:08
-
-
Save mrmt/4564284 to your computer and use it in GitHub Desktop.
はてなブックマークしたエントリがすでにpinboardに存在する場合、pinboard側の情報を上書きしない
This file contains 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/perl | |
# from http://d.hatena.ne.jp/amachang/20090603/1244025898 | |
use utf8; | |
use strict; | |
use warnings; | |
use CGI; | |
use Net::Delicious; | |
use Config::Pit; | |
use constant { | |
PINBOARD_ENDPOINT => 'https://api.pinboard.in/v1/', | |
}; | |
my $config = pit_get('hatena2pinboard', | |
require => { | |
hatena_webhook_key => 'xxx', | |
pinboard_username => 'xxx', | |
pinboard_password => 'xxx', | |
}); | |
die 'pit_get failed.' if !%$config; | |
my $req = CGI->new; | |
$req->charset('utf-8'); | |
print CGI::header('text/plain'); | |
if($req->param('key') eq $config->{hatena_webhook_key}){ | |
if($req->param('status') eq 'add'){ | |
my $url = $req->param('url'); | |
my $title = $req->param('title'); | |
my $comment = $req->param('comment'); | |
post_pinboard($url, $title, $comment); | |
} | |
} | |
print 'ok'; | |
exit; | |
################################################################ | |
sub post_pinboard{ | |
my $url = shift; | |
my $title = shift; | |
my $comment = shift; | |
my $pinboard = Net::Delicious->new({ | |
user => $config->{pinboard_username}, | |
pswd => $config->{pinboard_password}, | |
endpoint => PINBOARD_ENDPOINT | |
}); | |
$pinboard->add_post({ | |
url => $url, | |
description => $title, | |
extended => $comment, | |
replace => 0, | |
}); | |
} | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment