Browse Source

bin/pinboard: some hacky extra crap for search by tag

main
Brennen Bearnes 10 months ago
parent
commit
85ee33062f
1 changed files with 47 additions and 15 deletions
  1. +47
    -15
      home/bin/pinboard

+ 47
- 15
home/bin/pinboard View File

@ -13,22 +13,46 @@ use Carp;
use utf8;
use open qw(:std :utf8);
if ($ARGV[0] eq 'tags') {
if (defined $ARGV[0] && $ARGV[0] eq 'tags') {
print tags();
} elsif (defined $ARGV[0] && $ARGV[0] eq 'by-tag') {
croak "Must supply a tag name"
unless defined $ARGV[1];
print by_tag($ARGV[1]);
} else {
my $ISO_8601_FMT = '%Y-%m-%d';
print recent(Time::Piece->strptime('2020-03-02', $ISO_8601_FMT));
}
sub by_tag {
my $tag = shift;
my $token = get_token();
# lol this is terrible
my $url = 'https://api.pinboard.in/v1/posts/all?tag=' . $tag . '&format=json&auth_token=' . $token;
my $pinboard_json = `curl -s '${url}'`;
# print $url;
# print $pinboard_json;
my $JSON = JSON->new->utf8->pretty;
my $pinboard_hashref = $JSON->decode($pinboard_json);
my @posts = @{ $pinboard_hashref };
my @output;
foreach my $post (@posts)
{
# push @output, Dumper($post);
push @output,
"$post->{time}\t$post->{href}\t$post->{tags}\n";
}
return @output;
}
sub tags {
# See the bit about auth here:
# https://pinboard.in/api/
my $home = File::HomeDir->my_home;
my $token = file_get_contents("${home}/.pinboardrc");
chomp($token);
my $token = get_token();
my $url = 'https://api.pinboard.in/v1/tags/get?format=json&auth_token=' . $token;
my $pinboard_json = `curl -s '${url}'`;
# https://stackoverflow.com/questions/45941522/parsing-utf-8-json-with-perl
@ -44,13 +68,13 @@ sub tags {
$output .= "$tag\n";
}
return $output;
#
#
# my @output;
# foreach my $tag (@tags)
# {
# push @output, Dumper($tag);
# }
#
#
# if (@output > 0) {
# return join "\n", @output;
# }
@ -60,11 +84,7 @@ sub tags {
sub recent {
my ($day) = @_;
# See the bit about auth here:
# https://pinboard.in/api/
my $home = File::HomeDir->my_home;
my $token = file_get_contents("${home}/.pinboardrc");
chomp($token);
my $token = get_token();
my $url = $day->strftime(
'https://api.pinboard.in/v1/posts/get?dt=%Y-%m-%d&meta=yes&format=json&auth_token='
@ -79,7 +99,9 @@ sub recent {
my @output;
foreach my $post (@posts)
{
push @output, Dumper($post);
# push @output, Dumper($post);
push @output,
"$post->{href}\n$post->{tags}\n$post->{description}\n";
}
if (@output > 0) {
@ -106,3 +128,13 @@ sub file_get_contents {
return $contents;
}
sub get_token {
# See the bit about auth here:
# https://pinboard.in/api/
my $home = File::HomeDir->my_home;
my $token = file_get_contents("${home}/.pinboardrc");
chomp($token);
return $token;
}

Loading…
Cancel
Save