source: bookmarks/trunk/scan @ 72

Last change on this file since 72 was 72, checked in by peter, 11 years ago
  • added the access log file to svn:ignore
  • added the scan script to scan a bookmarks database and report how many links still appear to be active
  • Bookmarks::get_bookmarks() defaults its parameters to {} before passing them on to Bookmarks::Search
  • Property svn:executable set to *
File size: 784 bytes
RevLine 
[72]1#!/usr/bin/perl -w
2use strict;
3
4use Bookmarks;
5use LWP::UserAgent;
6use Text::CSV;
7use Getopt::Long;
8
9GetOptions(
10    'csv' => \my $CSV,
11    'timeout=i' => \my $TIMEOUT,
12);
13
14my $DBFILE = shift or die "Usage: $0 <dbfile>";
15
16$TIMEOUT ||= 10;
17
18my $bookmarks = Bookmarks->new({
19    dbname => $DBFILE,
20});
21
22my $ua = LWP::UserAgent->new;
23$ua->timeout($TIMEOUT);
24
25my $csv = Text::CSV->new;
26
27for my $bookmark (@{ $bookmarks->get_bookmarks->results }) {
28    printf "%3d %s\n", $bookmark->id, $bookmark->uri unless $CSV;
29    my $response = $ua->head($bookmark->uri);
30    printf "   -> %s\n", $response->status_line unless $CSV;
31    $csv->combine(
32        $bookmark->id,
33        $bookmark->uri,
34        $response->code,
35        $response->message,
36    );
37    print $csv->string . "\n" if $CSV;
38}
Note: See TracBrowser for help on using the repository browser.