Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export skype-history from *.db files to text
#! /usr/bin/env bash
# export skype-history from *.db files to text
function err()
{
echo "$1" > /dev/stderr
exit 1
}
function expt()
{
if [[ -z $(which sqlite3) ]]
then
err "Sqlite3 does not exist"
fi
if [ $# -eq 1 ]
then
USERNAME=$(basename $(dirname "$1"))
echo "Make dir "$USERNAME""
mkdir "$USERNAME"
cd "$USERNAME"
fi
echo "Work with $1"
echo "Export contact list"
sqlite3 "$1" "SELECT skypename, given_displayname from contacts;" > contacts
echo "Export chat history"
while read USER; do
echo "Export messages from "$USER""
sqlite3 "$1" "SELECT author, from_dispname, datetime(timestamp, 'unixepoch') as date, body_xml FROM Messages where dialog_partner = '$USER' ORDER BY timestamp;"> "$USER"
done < <(sqlite3 "$1" "SELECT DISTINCT(dialog_partner) FROM Messages;")
if [ $# -eq 1 ]
then
cd ..
fi
echo "Done!"
}
# parse argv
while [[ -n "$*" ]]; do
case "$1" in
"-h")
echo "USAGE $0 [-f filename] [-h]"
exit 0
;;
"-f")
shift
FILE=$1
if [[ ! -e "$FILE" ]]
then
err ""$FILE" does not exist"
else
expt "$FILE" "something else"
exit 0;
fi
;;
esac
shift
done
if [[ -z $(which skype) ]]
then
err "Skype does not exist.\nIf you want use script with the file use -f option"
fi
DIR=~/.Skype
echo $DIR
if [[ ! -d "$DIR" ]]
then
err "Can't find skype home dir"
fi
while read SKYPE_DB_PATH; do
expt "$SKYPE_DB_PATH"
done < <(find "$DIR" -name main.db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment