summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-12 01:38:12 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-12 01:39:51 -0400
commitfc9e97d0ef182489dd2bb029b20648a9182f2a90 (patch)
tree6241c31a5a45b37f9ccd42408936e898b251e966
parente9f4e69ad0e27a24b429d5a9a0d6f51e0e2fdab2 (diff)
downloadwww-pinboard-fc9e97d0ef182489dd2bb029b20648a9182f2a90.tar.gz
www-pinboard-fc9e97d0ef182489dd2bb029b20648a9182f2a90.zip
the progress stuff is not worthwhile
the sync process takes less than a second
-rw-r--r--bin/pinboard_export28
-rw-r--r--lib/WWW/Pinboard.pm10
2 files changed, 4 insertions, 34 deletions
diff --git a/bin/pinboard_export b/bin/pinboard_export
index 990915f..3e61a09 100644
--- a/bin/pinboard_export
+++ b/bin/pinboard_export
@@ -7,13 +7,11 @@ use warnings;
use DBI;
use Getopt::Long qw(:config pass_through);
use WWW::Pinboard;
-use Term::ProgressBar;
-my ($dsn, $token, $quiet);
+my ($dsn, $token);
GetOptions(
'dsn=s' => \$dsn,
'token=s' => \$token,
- 'quiet' => \$quiet,
);
die "--dsn is required" unless $dsn;
die "--token is required" unless $token;
@@ -45,32 +43,11 @@ if ($fromdt ge $api->update->{update_time}) {
exit(0);
}
-my $progress;
-
my $sth = $dbh->prepare(
'INSERT INTO posts (href, description, extended, tags, time, toread) VALUES (?, ?, ?, ?, ?, ?)'
);
-my $posts = $api->all(fromdt => $fromdt, progress => sub {
- my ($chunk, $res) = @_;
- if (!$progress && !$quiet && defined $res->{headers}{'content-length'}) {
- $progress = Term::ProgressBar->new({
- count => $res->{headers}{'content-length'},
- ETA => 'linear',
- });
- $progress->message("downloading new posts...");
- }
- $res->{content} .= $chunk;
- $progress->update(length($res->{content})) if $progress;
-});
-
-if (!$quiet) {
- $progress = Term::ProgressBar->new({
- count => scalar(@$posts),
- ETA => 'linear',
- });
- $progress->message('importing posts...');
-}
+my $posts = $api->all(fromdt => $fromdt);
for my $post (@$posts) {
$sth->execute(
@@ -81,7 +58,6 @@ for my $post (@$posts) {
$post->{time},
$post->{toread},
);
- $progress->update if $progress;
}
$dbh->commit;
diff --git a/lib/WWW/Pinboard.pm b/lib/WWW/Pinboard.pm
index 585924d..ffa39b5 100644
--- a/lib/WWW/Pinboard.pm
+++ b/lib/WWW/Pinboard.pm
@@ -24,9 +24,7 @@ This module is a basic client for the L<https://pinboard.in/> API. It currently
provides methods for each API method in the C<posts/> namespace (patches
welcome to add support for more methods). Each method takes a hash of
arguments, which correspond to the parameters documented in the API
-documentation at L<https://pinboard.in/api/>. They can also take an additional
-parameter C<progress>, which will be passed to the C<data_callback> parameter
-of the call to C<get> on the L<HTTP::Tiny> object.
+documentation at L<https://pinboard.in/api/>.
=cut
@@ -105,16 +103,12 @@ for my $method (qw(update add delete get recent dates all suggest)) {
my $self = shift;
my (%args) = @_;
- my $progress = delete $args{progress};
-
my $uri = $self->endpoint->clone;
# XXX eventually support other parts of the api
$uri->path($uri->path . 'posts/' . $method);
$uri->query_form($uri->query_form, %args);
- my $res = $self->ua->get(
- $uri, { $progress ? (data_callback => $progress) : () }
- );
+ my $res = $self->ua->get($uri);
die $res->{content} unless $res->{success};
return $self->json->decode($res->{content});
});