Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
2.0 KiB

#!/usr/bin/env perl
use strict;
use warnings;
use 5.10.0;
use File::HomeDir;
use JSON;
use Data::Dumper;
use Time::Piece;
use Carp;
if ($ARGV[0] eq 'tags') {
print tags();
} else {
my $ISO_8601_FMT = '%Y-%m-%d';
print recent(Time::Piece->strptime('2020-03-02', $ISO_8601_FMT));
}
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 $url = 'https://api.pinboard.in/v1/tags/get?format=json&auth_token=' . $token;
my $pinboard_json = `curl -s '${url}'`;
my $JSON = JSON->new->utf8->pretty;
my $pinboard_hashref = $JSON->decode($pinboard_json);
my %tags = %{ $pinboard_hashref };
my $output = '';
foreach my $tag (keys %tags) {
$output .= "$tag\n";
}
return $output;
#
# my @output;
# foreach my $tag (@tags)
# {
# push @output, Dumper($tag);
# }
#
# if (@output > 0) {
# return join "\n", @output;
# }
# return;
}
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 $url = $day->strftime(
'https://api.pinboard.in/v1/posts/get?dt=%Y-%m-%d&meta=yes&format=json&auth_token='
. $token
);
my $pinboard_json = `curl -s '${url}'`;
my $JSON = JSON->new->utf8->pretty;
my $pinboard_hashref = $JSON->decode($pinboard_json);
my @posts = @{ $pinboard_hashref->{posts} };
my @output;
foreach my $post (@posts)
{
push @output, Dumper($post);
}
if (@output > 0) {
return join "\n", @output;
}
return;
}
# PHP-style file-content grabbing:
sub file_get_contents {
my ($file) = @_;
open my $fh, '<', $file
or croak "Couldn't open $file: $!\n";
my $contents;
{
# line separator:
local $/ = undef;
$contents = <$fh>;
}
close $fh or croak "Couldn't close $file: $!";
return $contents;
}