Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Thanks for the nifty tool. I used this as the basis for a script to dump or analyze Firefox history. It has worked fine so far except that one time, after doing some reports, I started Firefox and got an error about the bookmarks and history being unavailable because the database was locked. I'm not sure why the script didn't unlock the places.sqlite database on closing, but restarting Firefox fixed the problem, and since then I've run the history analysis script and started Firefox again without error messages.

#! /usr/bin/perl use strict; use warnings; use DBD::SQLite; use feature 'switch'; no warnings 'experimental::smartmatch'; =pod Firefox history analyzer -- print all domains visited and the number of times visited, or a dump of all history URLs in chronological order based on firefox bookmarks exporter by jdporter https://www.perlmonks.org/?node_id=11113866 =cut sub usage { print <<USAGE; Usage: $0 [path-to-Firefox-profile/places.sqlite] [command] Command is one of: h -- list all history by date order. d -- List domains and visit counts, sorted by most often visited. Firefox must be closed for this to work, or you'll get "Database locke +d" errors. USAGE } sub unique_domains; sub list_visit_dates; my $dbfile = shift; $dbfile or usage, exit; -r $dbfile or die "Unreadable $dbfile\n"; $dbfile =~ /\bplaces\.sqlite$/ or die "File should be places.sqlite\n" +; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","") or die "Erro +r opening db $dbfile\n"; my $history = $dbh->selectall_hashref( q( SELECT moz_historyvisits.id, visit_date, url FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ), 'id' ); given ( $ARGV[0] ) { when ( undef ) { usage; } when( 'h' ) { list_visit_dates; } when( 'd' ) { unique_domains; } default { usage; } } sub unique_domains { my %domains; for my $k ( keys %$history ) { if ( $history->{$k}{url} =~ m! \w+:// ([^/]+) !x ) { $domains{ $1 }++; } } for my $d ( reverse sort { $domains{$a} <=> $domains{$b} || $a cmp + $b } keys %domains ) { printf "%4d\t%s\n", $domains{$d}, $d; } } # https://support.mozilla.org/en-US/questions/972178 indicates that # visit_date is a million times the Unix epoch date (with potentially # microsecond accuracy on some machines?) sub list_visit_dates { for my $k ( sort { my $c = $history->{$a}{visit_date} // 0; my $d = $history->{$b}{visit_date} // 0; $c <=> $d || $history->{$a}{url} cmp $history->{$a}{url} || $a <=> $b } keys %$history ) { my $t = $history->{$k}{visit_date} // 0; next unless $t; $t /= 1_000_000; printf "%20s %s\n", scalar localtime($t), $history->{$k}{url}; } }

In reply to Re: Export (extract) Mozilla Firefox Bookmarks by jimhenry
in thread Export (extract) Mozilla Firefox Bookmarks by jdporter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-10-02 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (12 votes). Check out past polls.

    Notices?