-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrealtimeskypelog.py
86 lines (78 loc) · 2.9 KB
/
realtimeskypelog.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Skype4Py
import time
import signal
import sqlite3
import sys
class SkypeHandler:
def __init__(self):
self.client = self.get_client()
self.client.Attach()
self.DB = False
try:
open('temp.db')
self.db = sqlite3.connect('temp.db', check_same_thread=False)
self.cursor = self.db.cursor()
self.DB = True
except Exception as e:
print e
print 'Database connect failed, write to stdout!'
def get_client(self):
""" Reveice Skype4Py.Skype instance
*** Maybe launch Skype if not launched?
"""
if sys.platform == "linux2":
skype = Skype4Py.Skype(Events=self, Transport='x11')
else:
# OSX, windows
skype = Skype4Py.Skype(Events=self)
if not skype.Client.IsRunning:
skype.Client.Start()
return skype
def MessageStatus(self, msg, status):
""" Skype event handler """
room = False
if (len(msg.Chat.Members) > 2): #chat room
label = msg.Chat.Topic
handle = msg.ChatName
icon = None
room = True
else: #individual chat
label = msg.FromDisplayName
handle = msg.FromHandle
nick = msg.FromHandle
name = msg.FromDisplayName
#print status
if status == Skype4Py.skype.cmsReceived:
if self.DB:
self.cursor.execute('''INSERT INTO messages(msg_id, name, topic,
nick, handle, body) VALUES(?,?,?,?,?,?)''',
(msg.Id, name, label, nick, handle, msg.Body))
self.db.commit()
else:
print handle, nick, '('+name+')', msg.Body
elif status == Skype4Py.skype.cmsSent:
if self.DB:
self.cursor.execute('''INSERT INTO messages(msg_id, name, topic,
nick, handle, body) VALUES(?,?,?,?,?,?)''',
(msg.Id, name, label, nick, handle, msg.Body))
self.db.commit()
else:
print handle, nick, '('+name+')', msg.Body
elif status == Skype4Py.skype.cmsUnknown:
if self.DB:
self.cursor.execute('''INSERT INTO messages(msg_id, name, topic,
nick, handle, body) VALUES(?,?,?,?,?,?)''',
(msg.Id, name, label, nick, handle, msg.Body))
self.db.commit()
else:
print handle, nick, '('+name+')', msg.Body
def MessageHistory(self, Username):
print Username
def attach_client(self):
""" tries to attach API to client """
self.client.Attach()
if __name__ == '__main__':
SkypeHandler()
signal.signal(signal.SIGINT, signal.SIG_DFL)
while True:
time.sleep(1000)