Changeset 120 in bookmarks for trunk/bin/bkmk
- Timestamp:
- 02/25/16 17:17:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/bkmk
r103 r120 6 6 7 7 use YAML; 8 use Getopt::Long ;8 use Getopt::Long qw{GetOptions GetOptionsFromArray :config pass_through}; 9 9 10 10 use Bookmarks; … … 12 12 GetOptions( 13 13 'file|f=s' => \my $DBNAME, 14 'title=s' => \my $TITLE,15 14 ); 16 15 … … 19 18 20 19 my $bookmarks = Bookmarks->new({ 21 dbname => $dbname,22 });20 dbname => $dbname, 21 }); 23 22 24 23 my $command = shift; … … 30 29 load_bookmarks($src_file) if $src_file; 31 30 }, 32 31 33 32 get => sub { 34 33 my $identifier = shift; … … 36 35 print $bookmark ? Dump($bookmark->to_hashref) : "Not Found\n"; 37 36 }, 38 37 39 38 add => sub { 39 GetOptionsFromArray( 40 \@_, 41 'title=s' => \my $TITLE, 42 ); 40 43 my ($uri, @tags) = @_; 41 44 my $title = defined $TITLE ? $TITLE : fetch_title($uri); … … 47 50 my @tags = @_; 48 51 my $resources = $bookmarks->search({ 49 tags => \@tags50 });52 tags => \@tags 53 }); 51 54 # TODO: list by tags, date, etc. 52 55 # TODO: coordinate this commandline script with the CGI app … … 80 83 $dump_file ? YAML::DumpFile($dump_file, $dump) : print Dump($dump); 81 84 }, 85 86 # scanning for current status 87 scan => sub { 88 GetOptionsFromArray( 89 \@_, 90 'csv' => \my $CSV, 91 'timeout=i' => \my $TIMEOUT, 92 ); 93 94 require LWP::UserAgent; 95 require Text::CSV; 96 97 $TIMEOUT ||= 10; 98 99 my $ua = LWP::UserAgent->new; 100 $ua->timeout($TIMEOUT); 101 102 my $csv = Text::CSV->new; 103 104 for my $bookmark (@{ $bookmarks->search->results }) { 105 printf "%3d %s\n", $bookmark->id, $bookmark->uri unless $CSV; 106 my $response = $ua->head($bookmark->uri); 107 printf " -> %s\n", $response->status_line unless $CSV; 108 $csv->combine( 109 $bookmark->id, 110 $bookmark->uri, 111 $response->code, 112 $response->message, 113 ); 114 print $csv->string . "\n" if $CSV; 115 } 116 }, 82 117 ); 83 118
Note: See TracChangeset
for help on using the changeset viewer.