#!/usr/bin/perl -w # read dcache4.url from Opera logs, write links and time. use Time::ParseDate; use POSIX qw(strftime); use strict; my $fh; my $t; my $url = ''; my $date = ''; #my $file = 'dcache4.url'; # TESTING my $file = shift || die "usage: $0 file\n"; # Get today's date starting at midnight. my $today = time(); my ($s, $m, $h) = (localtime($today))[0, 1, 2]; my $offset = ($h * 3600) + ($m * 60) + $s; $today -= $offset; # Read the strings from the URL cache file. open($fh, "/bin/strings $file |"); while (<$fh>) { chomp; # order: link, then *first* date string, then "opr". if (m!^.(.*://.*)!) { $url = $1; $date = ''; } elsif (m!^(.* GMT)!) { if ($t = parsedate($1)) { if ($t >= $today) { $date = strftime("%T", localtime($t)); } } } elsif (m!^opr! || m!\(!) { if ($url =~ m/\.(png|css|jpg|gif)$/) { $url = ''; } if ($url =~ m!http://example.com/!) { $url = ''; } if (length($url)) { $date = '??:??:??' unless length($date); print "$date $url\n"; $url = $date = ''; } } } close($fh); exit(0);