Changeset 83 in bookmarks
- Timestamp:
- 06/03/15 20:21:19 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bkmk
r47 r83 2 2 use strict; 3 3 4 use FindBin; 5 use lib "$FindBin::RealBin/lib"; 6 4 7 use YAML; 8 use Getopt::Long; 9 5 10 use Bookmarks; 6 use Getopt::Long;7 11 8 12 GetOptions( 9 13 'file|f=s' => \my $DBNAME, 10 't ag=s' => \my @TAGS,14 'title=s' => \my $TITLE, 11 15 ); 12 16 13 die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME; 17 my $dbname = $DBNAME || $ENV{BKMK_DBNAME}; 18 die "Usage: $0 --file <dbname> <command>\n" unless $dbname; 14 19 15 20 my $bookmarks = Bookmarks->new({ 16 dbname => $ DBNAME,21 dbname => $dbname, 17 22 }); 18 23 … … 23 28 $bookmarks->create_tables; 24 29 }, 30 25 31 get => sub { 26 32 my $identifier = shift; … … 30 36 print $bookmark ? Dump($bookmark) : "Not Found\n"; 31 37 }, 38 32 39 add => sub { 33 my ($uri, $title, @tags) = @_; 40 my ($uri, @tags) = @_; 41 my $title = defined $TITLE ? $TITLE : fetch_title($uri); 34 42 my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags }); 35 43 print Dump($bookmark); 36 44 }, 45 37 46 list => sub { 47 my @tags = @_; 38 48 my @resources = $bookmarks->get_bookmarks({ 39 tag => \@ TAGS49 tag => \@tags 40 50 }); 41 51 # TODO: list by tags, date, etc. … … 43 53 print Dump(\@resources); 44 54 }, 55 56 # bulk loading 45 57 load => sub { 46 58 my ($src_file) = @_; … … 54 66 $action_for{$command}->(@ARGV); 55 67 56 =begin 57 58 use YAML; 59 68 sub fetch_title { 69 my $uri = shift; 70 require WWW::Mechanize; 71 my $mech = WWW::Mechanize->new; 72 $mech->get($uri); 73 return $mech->title || $uri; 74 }
Note: See TracChangeset
for help on using the changeset viewer.