arnarg

Gmail notifier

Mar 8th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import feedparser, pynotify
  3.  
  4. checkerFile = '.checker'
  5.  
  6. def checkLast(current): # Checks if the email count is the same as last time (no NEW email)
  7.     f = open(checkerFile, 'r')
  8.     last = f.read();
  9.     f.close()
  10.     if last == current:
  11.         return True
  12.     else:
  13.         f = open(checkerFile, 'w')
  14.         f.write(current)
  15.         f.close()
  16.         return False
  17.  
  18. try:
  19.     g = feedparser.parse('https://[email protected]:[email protected]/mail/feed/atom') # Checking Gmail
  20.     count = g.feed.fullcount # Putting the count into a variable
  21. except Exception: # If there is an Exception the program exits
  22.     exit()
  23.  
  24. if count == '0': # No need to notify me if there is no email
  25.     checkLast(count) # but still want to update the checker file
  26. else:
  27.     if checkLast(count): # If the email count is the same as was saved in the text file last, there's no new email
  28.         pass
  29.     else:
  30.         pynotify.init("summary-body") # Setting up the notification
  31.         if count == "1":
  32.             n = pynotify.Notification("GMail", "{0} new email".format(count))
  33.         else:
  34.             n = pynotify.Notification("GMail", "{0} new emails".format(count))
  35.         n.show() # Displaying the notification
Advertisement
Add Comment
Please, Sign In to add comment