1

I am working on a script to get information from the Skype database. I got the following code:

con = sqlite3.connect('C:\\Users\\joey\\AppData\\Roaming\\Skype\\jre93\\main.db')

But the skype ID (jre93) and the USER (joey) of the computer are always different. Is there a way python can recognize those path automatic with out user input?

joey
  • 221
  • 3
  • 15
  • 1
    The home directory you can get from 'from os.path import expanduser home = expanduser("~")' see http://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python – Keith John Hutchison Jun 14 '15 at 12:23
  • 2
    The skype id is likely to be the only directory in the Skype folder. If more than one you could either check on last date modified or ask the user. – Keith John Hutchison Jun 14 '15 at 12:25
  • 1
    @csmu Thanks for the tip on last date modified :)! I dont wanna ask the user for hes skype name – joey Jun 14 '15 at 12:28

1 Answers1

2

Usually the folder with name of skype ID contains the main.db file! So we can use this fact to get the skype ID.

One method to do so is to first check if there is any skype folder at that particular path. Then find the folder in the skype folder, that contains the main.db file. If a folder is found then the name of this folder is the skype ID.

I have created a small quick and dirty script for this work. (It can be further improved)

Code:

import getpass
import os
import sys

userName = getpass.getuser() #Get the username
path = "C:\\Users\\"+userName+"\\AppData\\Roaming\\Skype\\"

if (os.path.isdir(path)) == True: #Check if Skype folder exists
    subdirectories = os.listdir(path)
    for i in subdirectories:
        if os.path.isdir(path+i) == True:
            if os.path.exists(path+i+"\\main.db"):
                print ("Skype Id is %s") %i

else:
    print 'Skype folder does not exists'

I hope it was helpful.

ρss
  • 4,577
  • 7
  • 35
  • 69