Create a gist now

Instantly share code, notes, and snippets.

@hwdsl2 /README.md
Last active Dec 7, 2016

What would you like to do?
Bash script for generating your detailed Google Voice call history

Get Your Detailed Google Voice Call History

Use this bash script to process your Google Voice archive from Google Takeout, and output your detailed call history in a tabular format for easy viewing and analysis.

Link to my blog article with detailed instructions

Learn how to set up your personal VoIP server

↓  ↓  ↓ Scroll down for the script ↓  ↓  ↓

License

Copyright (C) 2014-2015 Lin Song View my profile on LinkedIn

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Analytics

#!/bin/bash
#
# call_stats.sh is a bash script to process your Google Voice archive downloaded
# from Google Takeout, and output your call history in an easy-to-read format.
#
# Copyright (C) 2014-2015 Lin Song
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see http://www.gnu.org/licenses/.
for PG in sed stat grep paste column; do
command -v ${PG} >/dev/null 2>&1 || { echo >&2 "I require \"${PG}\" but it's not installed. Aborting."; exit 1; }
done
sw=0
for DR in Received Placed Missed; do
if ls -- *-\ ${DR}\ -*.html &> /dev/null; then sw=1; fi
done
[ "$sw" = "0" ] && { echo "No call history files found. Please double check your current folder is \"Calls\". Aborting."; exit 1; }
echo "Processing, please wait ..."
mkdir -p mytempdir
/bin/rm -f mytempdir/*
/bin/cp -f -- *.html mytempdir/
cd mytempdir || { echo "Failed to change working directory to mytempdir. Aborting."; exit 1; }
/bin/rm -f -- *-\ Voicemail\ -*
/bin/rm -f -- *-\ Text\ -*
for FL in *; do
/bin/mv -f -- "${FL}" "`stat -c %n -- "${FL}" | sed -e 's/.*- Received/Received/' -e 's/.*- Placed/Placed/' -e 's/.*- Missed/Missed/'`" &> /dev/null
done
for DR in Received Placed Missed; do
if ! ls -- *${DR}\ -* &> /dev/null; then continue; fi
echo "Contact_Name" > 1.txt
echo "Phone_Number" > 2.txt
echo "Start_Date Start_Time Timezone" > 3.txt
echo "Call_Duration" > 4.txt
# Contact Name
cat -- *${DR}\ -* | grep "tel:" | sed -e "s/<a.*\"fn\">//" -e "s/<\/span.*//" -e "s/^$/_EMPTY_/" >> 1.txt
# Telephone Number
cat -- *${DR}\ -* | grep "tel:" | sed -e "s/<a.*tel://" -e "s/\"><span.*//" -e "s/^$/_EMPTY_/" >> 2.txt
# Date, Time and Timezone
cat -- *${DR}\ -* | grep "\"published" | sed -e "s/<abbr.*title=\"//" -e "s/\">.*//" -e "s/\.000/ UTC/" -e "s/Z//" -e "s/T/ /" >> 3.txt
if [ ! "$DR" = "Missed" ]; then
# Call Duration
cat -- *${DR}\ -* | grep "duration" | sed -e "s/<abbr.*(//" -e "s/).*//" >> 4.txt
paste -d '|' 1.txt 2.txt 3.txt 4.txt | column -t -s '|' > ${DR}_calls.txt
else
paste -d '|' 1.txt 2.txt 3.txt | column -t -s '|' > ${DR}_calls.txt
fi
/bin/rm -f 1.txt 2.txt 3.txt 4.txt
/bin/rm -f -- *${DR}\ -*
grep -E -v -e "+1(800|888|877|866|855|844)[[:digit:]]{7}" ${DR}_calls.txt > ${DR}_calls_without_US_toll_free_numbers.txt
done
if ls -- *.html &> /dev/null; then
echo "Additional call history files found (possibly Google Hangouts calls). Processing ..."
for FL in *.html; do
/bin/mv -f -- "${FL}" "`stat -c %n -- "${FL}" | sed -e 's/.*- 20/20/'`"
done
echo "Contact_Name" > 1.txt
echo "Phone_Number" > 2.txt
echo "Start_Date Start_Time Timezone" > 3.txt
echo "Call_Duration" > 4.txt
# Contact Name
cat -- *.html | grep "tel:" | sed -e "s/<a.*\"fn\">//" -e "s/<\/span.*//" -e "s/^$/_EMPTY_/" >> 1.txt
# Telephone Number
cat -- *.html | grep "tel:" | sed -e "s/<a.*tel://" -e "s/\"><span.*//" -e "s/^$/_EMPTY_/" >> 2.txt
# Date, Time and Timezone
cat -- *.html | grep "\"published" | sed -e "s/<abbr.*title=\"//" -e "s/\">.*//" -e "s/\.000/ UTC/" -e "s/Z//" -e "s/T/ /" >> 3.txt
# Call Duration
cat -- *.html | grep "duration" | sed -e "s/<abbr.*(//" -e "s/).*//" >> 4.txt
paste -d '|' 1.txt 2.txt 3.txt 4.txt | column -t -s '|' > Other_calls.txt
/bin/rm -f 1.txt 2.txt 3.txt 4.txt
grep -E -v -e "+1(800|888|877|866|855|844)[[:digit:]]{7}" Other_calls.txt > Other_calls_without_US_toll_free_numbers.txt
fi
cd ..
mkdir -p GV_CSV_Files
/bin/rm -f GV_CSV_Files/*
/bin/cp -f mytempdir/*calls*.txt GV_CSV_Files/
if [ $? -eq 0 ]; then
echo
echo "Results successfully generated."
echo
echo "Please open the call history text files in folder Calls\GV_CSV_Files."
echo "There are additional result files without U.S. Toll-Free numbers."
echo "Use WordPad to open them (Right-click, Open with, select WordPad)."
else
echo "Oops... Something went wrong. No result is generated."
fi
echo
echo -n "Removing temp directory..."
/bin/rm -f mytempdir/*
rmdir mytempdir
echo " Done."

Thanks for the useful script.

Not sure what the stat call does, but for OSX, the format for stat should be

stat -f %N -- "$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment