Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created September 4, 2011 04:24
Show Gist options
  • Save mmisono/1192261 to your computer and use it in GitHub Desktop.
Save mmisono/1192261 to your computer and use it in GitHub Desktop.
#/usr/bin/python
import Skype4Py
import Growl
import os
import sqlite3
import shutil
import time
handle_names = []
names_of_chats = []
def get_avatar_images():
db_path = os.path.expanduser('~/Library/Application Support/Skype/mfumi2/main.db')
tmp_dir = '/tmp/skype'
tmp_db = os.path.join(tmp_dir,"main.db")
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
shutil.copyfile(db_path,tmp_db)
conn = sqlite3.connect(tmp_db)
cursor = conn.execute("SELECT skypename,avatar_image from Contacts")
global images_of_avatars
images_of_avatars = dict()
for name,avatar in cursor.fetchall():
img_name = os.path.join(tmp_dir,name+".jpg")
img = open(img_name,"wb")
if avatar != None:
# the beginning of avatar images is a NULL byte
# (i don't know why...)
img.write(avatar[1:])
img.close()
images_of_avatars[name] = Growl.Image.imageFromPath(img_name)
cursor.close()
conn.close()
def configure_growl():
global growl
growl = Growl.GrowlNotifier(applicationName = 'SkypeNotify',
notifications = ['Message','Status'])
growl.register()
def OnMessageStatus(message,status):
if status == "RECEIVED" and \
len(message.Body) > 0 :
if message.Chat.Name in names_of_chats:
global growl,images_of_avatars
growl.notify(noteType = 'Message',
title = message.FromDisplayName,
description = message.Body,
icon = images_of_avatars.get(message.FromHandle),
sticky = False)
def OnOnlineStatus(user,status):
if user.Handle in handle_names:
global growl,images_of_avatars
growl.notify(noteType = 'Status',
title = user.FullName,
description = status,
icon = images_of_avatars.get(user.Handle),
sticky = False)
if __name__ == "__main__":
print "getting avatar images..."
get_avatar_images()
print "done."
configure_growl()
skype = Skype4Py.Skype()
skype.OnMessageStatus = OnMessageStatus
skype.OnOnlineStatus = OnOnlineStatus
skype.Attach()
print "\nstart..."
while True:
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment