Home: Perl Programming Help: Beginner:
Please help with a PERL Script for Google Voice Call Log (Google Takeout)

New User

Aug 2, 2012, 4:43 PM

Views: 1599
Please help with a PERL Script for Google Voice Call Log (Google Takeout)

Using Google Takeout, I downloaded my Google Voice call logs.

Google does that in a very wierd way (for some, this is not surprising). The call log consists of a "Call" directory in which each call is an individual HTML file.

So if you made 855 calls, you have 855 .html files in the directory.

I want the list in an excel spreadsheet like this:

Date Time Type User Number Duration
02-Aug-2012 20:44:22 Placed Joe Smith 12035551212 0:00:17

My original perl code (below) goes through each .html file and produces a single spreadsheet called calls2.xls
....but Google changed the way they produce the HTML files....

Now.. the PERL script gives me everything but the DATE and TIME
(I am using this on a Win7 Machine with ActivePerl)

Any help getting the Date and Time in the excel spreadsheet would be great.

PERL CODE (Outside the 'Calls' Directory):

#!/usr/bin/perl -w 
$ncalls = 0;
$path = "Calls";
opendir(DIR, $path) or die "can't open $path folder";
open(OUT, ">calls2.csv") or die "can't write CSV file";
print OUT "Date,Time,Type,User,Number,Duration\n";
for $fname (readdir(DIR)) {
next unless $fname =~ /\.html$/ && open(IN, "$path\/$fname");
$date = $time = $type = $user = $number = $duration = '';
while (<IN>) {
$user = <IN>, $user =~ s/<.+\n// if /Call Log for/;
$type = $1 if />(Placed|Received|Missed|Voicemail) (call |from)/;
$number = $1 if /tel:\+(\d+)/;
$date =~ s#(\d+)/(\d+)/(\d+)#$3/$1/$2#;
$time = $1 if />([\w,: ]+)<\/abbr>/;
$duration = '00:00:00' if $type eq 'Missed' && $date;
$duration = $1 if />\(([\d:]+)\)<\/abbr>/;
if ($duration) {
print OUT "\"$date\",\"$time\",$type,\"$user\",$number,$duration\n";
print "processed $ncalls calls\n";

In the calls directory attached are how 2 .html files look:

Received call:
Filename: +15165551212_-_2012-07-23T14-47-35Z.html

This is a placed call:
Filename : +14085551213_-_2012-07-30T16-18-44Z.html

(This post was edited by yorktown on Aug 2, 2012, 11:38 PM)
Attachments: del1-recd-call.html (1.68 KB)
  del2-placed-call.html (1.66 KB)