Uncategorized

Scripts to retrieve call and billing history from Vonage

Since I’m parting ways with Vonage, I thought I’d like to download all of the data I could from my account. A quick modification to my voicemail script enabled me to download my call and billing history.

Here’s the perl script I used to retrieve my call history:

#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use File::Basename;
use HTTP::Response;
use HTTP::Headers;
use HTML::TokeParser;

my $UserName = 'myusername';
my $Password = 'mypassword';
my $AcctDesc = 'vonage';
my $link;
my $fields;
my $url;
my $filename;
my $response;
my $headers;
my $weeknum;
my $mech = WWW::Mechanize->new();

print "Logging in...\n";
$mech->agent_alias( 'Linux Mozilla' );
$mech->get( 'https://secure.vonage.com/vonage-web/public/login.htm' );

$fields = {
        'username' => $UserName,
        'password' => $Password,
        'goToSelection' => 'voicemail',
};
$mech->submit_form(
        form_name => 'logonForm',
        fields => $fields,
);
print "Going to Activity page...\n";
#Find the link for "Activity"
$mech->follow_link( text_regex => qr/Activity/ );
$mech->success or die "post failed: ", $mech->response->status_line;

print "Saving recent activity...\n";
$weeknum=0;
$filename = "call-activity-week-".$weeknum.".html";
print $filename . " saved\n";
open(outfile, ">$filename");
print outfile $mech->content;
close(outfile);

#I chose to use the Previous 7 Days method instead of Vonage's advanced search because it returns more results per page.

while ($mech->follow_link( text_regex => qr/Previous 7 Days/ ) ) {
#warning...this loop will keep going infinitely since they have a "Previous 7 Days" link that returns a page with no results.
        $weeknum++;
        $filename = "call-activity-week-".$weeknum.".html";
        print $filename . " saved\n";
        open(outfile, ">$filename");
        print outfile $mech->content;
        close(outfile);
}

132 saved pages later (man, I’m glad I didn’t have to do that manually.) It was done with my call history.

There is one bug in this script. It doesn’t know when to stop. I had to manually kill it when I started seeing many files being saved that were all 16.2KB in size. Since this was a one-time run of this script, it served its purpose. If someone wants to fix it so it stops at the right time, I’ll be more than happy to post an updated script to this page.

Now onto the billing history. This script seemed to work fine. It saved all of the information I wanted, except the printer friendly version didn’t quite work. The important thing is it’s all there and I can parse through it later if I want to.

Here’s my billing history script.

#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use File::Basename;
use HTTP::Response;
use HTTP::Headers;
use HTML::TokeParser;

my $UserName = 'myusername';
my $Password = 'mypassword';
my $AcctDesc = 'vonage';
my $link;
my $fields;
my $url;
my $filename;
my $response;
my $headers;
my $docnum;
my $mech = WWW::Mechanize->new();

print "Logging in...\n";
$mech->agent_alias( 'Linux Mozilla' );
$mech->get( 'https://secure.vonage.com/vonage-web/public/login.htm' );

$fields = {
        'username' => $UserName,
        'password' => $Password,
        'goToSelection' => 'voicemail',
};
$mech->submit_form(
        form_name => 'logonForm',
        fields => $fields,
);
print "Going to Activity page...\n";
#Find the link for "Activity"
$mech->follow_link( text_regex => qr/Billing/ );
$mech->success or die "post failed: ", $mech->response->status_line;

$mech->follow_link( text_regex => qr/Billing History/ );
$mech->success or die "post failed: ", $mech->response->status_line;

print "Saving billing history page...\n";
$filename = "billing-history-summary.html";
print $filename . " saved\n";
open(outfile, ">$filename");
print outfile $mech->content;
close(outfile);

$docnum=0;
my @links = $mech->find_all_links( text_regex => qr/Invoice/ );
for $link ( @links ) {
        $url = $link->url_abs;
        print "retrieving " . $url . "\n";
        $mech->get( $url );
        $response = $mech->response();
        #this header outputs in this format - "attachment;filename=18014671267-18012720998-08-01-2005-20-40-.wav"
        $filename = "invoice-".$docnum.".html";
        print $filename . " saved\n";
        open(outfile, ">$filename");
        print outfile $mech->content;
        close(outfile);
        $mech->follow_link( text_regex => qr/Printable Version/ );
        $mech->success or die "post failed: ", $mech->response->status_line;
        $filename = "printable-invoice-".$docnum.".html";
        print $filename . " saved\n";
        open(outfile, ">$filename");
        print outfile $mech->content;
        close(outfile);
        $mech->back();
        $mech->back();
        $docnum++;
}

$docnum=0;
my @links = $mech->find_all_links( text_regex => qr/Payment/ );
for $link ( @links ) {
        $url = $link->url_abs;
        print "retrieving " . $url . "\n";
        $mech->get( $url );
        $response = $mech->response();
        $filename = "payment-".$docnum.".html";
        print $filename . " saved\n";
        open(outfile, ">$filename");
        print outfile $mech->content;
        close(outfile);
        $mech->back();
        $docnum++;
}

$docnum=0;
my @links = $mech->find_all_links( text_regex => qr/Credit/ );
for $link ( @links ) {
        $url = $link->url_abs;
        print "retrieving " . $url . "\n";
        $mech->get( $url );
        $response = $mech->response();
        $filename = "credit-".$docnum.".html";
        print $filename . " saved\n";
        open(outfile, ">$filename");
        print outfile $mech->content;
        close(outfile);
        $mech->back();
        $docnum++;
}

Well, I have all of the information I want from my Vonage account. If I feel like it, maybe I’ll write another script later that parses it and give me some useful information.

  1. shyam

    July 22, 2011 at 12:09 pm

    Hi,
    I would like to download history of call placed and received on Vonage. I used your call history script and added username and passwoared. It did not work. Can you pl help me on this?
    Thanks,
    Shyam

    1. AltJ

      July 22, 2011 at 12:17 pm

      What’s the error you’re seeing? I just tried it out and got “Can’t call method “url” on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 713.” which might be related to this bug in Mechanize.

Comments are closed.