Guest User

Untitled

a guest
Jan 22nd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #/usr/bin/python
  2.  
  3. import Skype4Py
  4. import Growl
  5. import os
  6. import sqlite3
  7. import shutil
  8. import time
  9.  
  10. handle_names = []
  11. names_of_chats = []
  12.  
  13. def get_avatar_images():
  14. db_path = os.path.expanduser('~/Library/Application Support/Skype/mfumi2/main.db')
  15. tmp_dir = '/tmp/skype'
  16. tmp_db = os.path.join(tmp_dir,"main.db")
  17.  
  18. if not os.path.exists(tmp_dir):
  19. os.mkdir(tmp_dir)
  20. shutil.copyfile(db_path,tmp_db)
  21.  
  22. conn = sqlite3.connect(tmp_db)
  23. cursor = conn.execute("SELECT skypename,avatar_image from Contacts")
  24.  
  25. global images_of_avatars
  26. images_of_avatars = dict()
  27.  
  28. for name,avatar in cursor.fetchall():
  29. img_name = os.path.join(tmp_dir,name+".jpg")
  30. img = open(img_name,"wb")
  31. if avatar != None:
  32. # the beginning of avatar images is a NULL byte
  33. # (i don't know why...)
  34. img.write(avatar[1:])
  35. img.close()
  36. images_of_avatars[name] = Growl.Image.imageFromPath(img_name)
  37.  
  38.  
  39. cursor.close()
  40. conn.close()
  41.  
  42.  
  43. def configure_growl():
  44. global growl
  45. growl = Growl.GrowlNotifier(applicationName = 'SkypeNotify',
  46. notifications = ['Message','Status'])
  47. growl.register()
  48.  
  49.  
  50. def OnMessageStatus(message,status):
  51. if status == "RECEIVED" and \
  52. len(message.Body) > 0 :
  53. if message.Chat.Name in names_of_chats:
  54. global growl,images_of_avatars
  55. growl.notify(noteType = 'Message',
  56. title = message.FromDisplayName,
  57. description = message.Body,
  58. icon = images_of_avatars.get(message.FromHandle),
  59. sticky = False)
  60.  
  61. def OnOnlineStatus(user,status):
  62. if user.Handle in handle_names:
  63. global growl,images_of_avatars
  64. growl.notify(noteType = 'Status',
  65. title = user.FullName,
  66. description = status,
  67. icon = images_of_avatars.get(user.Handle),
  68. sticky = False)
  69.  
  70.  
  71. if __name__ == "__main__":
  72. print "getting avatar images..."
  73. get_avatar_images()
  74. print "done."
  75. configure_growl()
  76. skype = Skype4Py.Skype()
  77. skype.OnMessageStatus = OnMessageStatus
  78. skype.OnOnlineStatus = OnOnlineStatus
  79. skype.Attach()
  80. print "\nstart..."
  81. while True:
  82. time.sleep(1)
Add Comment
Please, Sign In to add comment