Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 11th, 2012  |  syntax: None  |  size: 1.18 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import pynotify
  2. import time
  3. import os
  4. import sys
  5. pynotify.init("test")
  6.  
  7. def pushNotification (title, body, icon):
  8.    3 lines:    n = pynotify.Notification (title, body, icon) ---------------------------------------------
  9.    
  10. def makeMessage (i):
  11.    9 lines:    old_message = os.popen(i).read().strip() --------------------------------------------------
  12.  
  13. initial_input_list = os.popen("ls /home/daniel/log | grep -v \# | grep -v \& | grep -v server | grep -v   core\.wee").readlines()
  14. buffer_list = []
  15.  
  16. for s in initial_input_list:
  17.     buffer_list.append(s.strip())
  18.  
  19. oldnotifications = {}
  20. while 1:
  21.     try:
  22.         for b in buffer_list:
  23.             try:
  24.                 if oldnotifications[b] != str(os.stat("/home/daniel/log/" + b)):
  25.                     i="tail -n1 /home/daniel/log/" + b
  26.                     title,message = makeMessage(i)
  27.                     pushNotification(title, message, "notification-message-im")
  28.                     oldnotifications[b] = str(os.stat("/home/daniel/log/" + b))
  29.             except KeyError:
  30.                 oldnotifications[b] = str(os.stat("/home/daniel/log/" + b))
  31.         time.sleep(.1)
  32.     except KeyboardInterrupt:
  33.         sys.exit(0)