From Bitty Capybara, 1 Week ago, written in Plain Text.
  1. #!/usr/bin/env python
  2.  
  3. import pygtk
  4. pygtk.require('2.0')
  5. import pynotify
  6. import sys
  7. import commands
  8. import time
  9. import logging
  10.  
  11.  
  12. argv = sys.argv
  13. fortune = []
  14.  
  15.  
  16. def usage():
  17.     """ Print usage message """
  18.     print ("usage: " + argv[0] + " message | title message")
  19.  
  20. def dbglog():
  21.     logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
  22.     logging.debug(sys.exc_info())
  23.  
  24. ### TODO: Parse command line arguments
  25. def parse():
  26.     """ Parse args for fortune program and this script """
  27.     ### /usr/games/fortune [-aefilosw] [-m pattern] [[N%] file/dir/all]
  28.     ### fortunedaemon.py [-t timeout]
  29.  
  30. def speak():
  31.     """ Display our fortune with dbus notification system """
  32.  
  33.     if not pynotify.init("fortunedaemon"):
  34.         sys.exit(1)
  35.  
  36.     dbglog()
  37.     fortune = commands.getoutput("/usr/games/fortune")
  38.  
  39.     n = pynotify.Notification("", fortune)
  40.  
  41.     n.set_timeout(20000)
  42.  
  43.     dbglog()
  44.     if not n.show():
  45.         print "Failed to send notification"
  46.         sys.exit(1)
  47.  
  48.  
  49. def main():
  50.  
  51.     dbglog()
  52.     #parse()
  53.     while True:
  54.         dbglog()
  55.         speak()
  56.         dbglog()
  57.         ### Sleep() takes number of seconds as arg. 900 is 15m
  58.         time.sleep(9)
  59.         dbglog()
  60.  
  61.  
  62.  
  63.  
  64. main()
  65. dbglog()
captcha