Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 16th, 2013  |  syntax: Python  |  size: 0.77 KB  |  views: 213  |  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. #!/usr/bin/python
  2. import praw, time, subprocess
  3.  
  4. def send_message(notify_text):
  5.         subprocess.Popen(["notify-send", "Reddit Notifier", notify_text])
  6.         return
  7.        
  8. r = praw.Reddit('Reddit Monitor for /u/YourUsername')
  9.  
  10. USER = 'YourUsername'
  11. PASS = 'YourPassword'
  12.  
  13. r.login(USER, PASS)
  14.  
  15. names = []
  16.  
  17. send_message("Reddit Notifier started.")
  18.  
  19. while True:
  20.         inbox = r.get_unread()
  21.         messages = []
  22.         new_names = []
  23.         for i in inbox:
  24.                 if not i.name in names:
  25.                         new_names.append(i.name)
  26.                         messages.append((i.subject, i.author.name))
  27.         names = new_names
  28.         count = len(messages)
  29.         if count > 0:
  30.                 send_message("You have %d unread message%s in your inbox.\n\n%s" % (count, "" if count == 1 else "s", "\n".join(["'%s' from /u/%s" % (m[0], m[1]) for m in messages])))
  31.         time.sleep(10)