-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskypelogs.py
executable file
·71 lines (61 loc) · 1.82 KB
/
skypelogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
import sqlite3
import argparse
def getLog(partner, path):
con = sqlite3.connect(path)
cur = con.cursor()
#
log = []
#get log for partner
getLog = """ SELECT
author,
from_dispname,
datetime(timestamp, 'unixepoch') as date,
body_xml
FROM Messages where dialog_partner = '{partner}' ORDER BY timestamp """
query = getLog.format(partner=partner)
cur.execute(query)
all = cur.fetchall()
for record in all:
if record:
# record is tuple: (from: acct name, from: display name, timestamp, message)
acct,display,timestamp,message = record
messagetext = ""
if message:
messagetext = message.encode('utf-8')
log.append( {'time':timestamp, 'name':display, 'message':messagetext } )
con.close()
return log
def getPartners(path):
con = sqlite3.connect(path)
cur = con.cursor()
#
partners = []
#list partners
getPartners = "SELECT DISTINCT(dialog_partner) FROM Messages;"
query = getPartners
cur.execute(query)
all = cur.fetchall()
for record in all:
if record[0]:
partners.append(str(record[0]))
con.close()
return partners
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument("path", help="path to the skype user's main.db file")
parser.add_argument("-u","--user",type=str, help="username with whom we want a conversation log")
parser.add_argument("-l","--list",help="list all users with whom we have communicated",action="store_true")
args = parser.parse_args()
if args.user:
outputfmt = "[{time}] {name}:\n-------------------\n{message}\n-------------------\n"
log = getLog(args.user,args.path)
for record in log:
print outputfmt.format(\
time=record['time'],\
name=record['name'],\
message=record['message'])
if args.list:
partners = getPartners(args.path)
for partner in partners:
print partner