Advertisement
Guest User

Untitled

a guest
Jan 16th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.23 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #========================================================================
  4. #      Copyright 2007 Raja <rajajs@gmail.com>
  5. #
  6. #      This program is free software; you can redistribute it and/or modify
  7. #      it under the terms of the GNU General Public License as published by
  8. #      the Free Software Foundation; either version 2 of the License, or
  9. #      (at your option) any later version.
  10. #
  11. #      This program is distributed in the hope that it will be useful,
  12. #      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #      GNU General Public License for more details.
  15. #
  16. #      You should have received a copy of the GNU General Public License
  17. #      along with this program; if not, write to the Free Software
  18. #      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #==========================================================================
  20.  
  21. # ======================================================================
  22. # Modified from code originally written by Baishampayan Ghose
  23. # Copyright (C) 2006 Baishampayan Ghose <b.ghose@ubuntu.com>
  24. # ======================================================================
  25.  
  26.  
  27. import urllib            
  28. import feedparser        
  29.  
  30. _url = "https://mail.google.com/gmail/feed/atom"
  31.  
  32. ##################   Edit here      #######################
  33.  
  34. #pwd =                            # pwd stored in script
  35. _pwdfile = '/path/to/pass/file'  # pwd stored in a file
  36. _username = 'username'
  37. _calmcolor = 'white'
  38. _alertcolor = 'white'
  39. _maxmails = 5  # maximum new mails to show
  40. _maxwords = 3  # maximum words to show in each mail header
  41.  
  42. ###########################################################
  43.  
  44. class GmailRSSOpener(urllib.FancyURLopener):
  45.     '''Logs on with stored password and username
  46.       Password is stored in a hidden file in the home folder'''
  47.    
  48.     def prompt_user_passwd(self, host, realm):
  49.         #uncomment line below if password directly entered in script.
  50.         pwd = open(_pwdfile).read()
  51.         return (_username, pwd)
  52.  
  53. def auth():
  54.     '''The method to do HTTPBasicAuthentication'''
  55.     opener = GmailRSSOpener()
  56.     f = opener.open(_url)
  57.     feed = f.read()
  58.     return feed
  59.  
  60. def showmail(feed):
  61.     '''Parse the Atom feed and print a summary'''
  62.     atom = feedparser.parse(feed)
  63.     newmails = len(atom.entries)
  64.     if newmails == 0:
  65.         title = "^fg(%s)no new mails" % (_calmcolor)
  66.     elif newmails == 1:
  67.         title = "^fg(%s)1 new mail"  % (_alertcolor)
  68.     else:
  69.         title = "^fg(%s)%s new mails" % (_alertcolor,newmails)
  70.    
  71.     # print the title with formatting
  72.     print "^tw()" +title
  73.     #clear the slave window
  74. #    print "^cs()"
  75.    
  76.     #then print the messages
  77.     for i in range(min(_maxmails,newmails)):
  78.        
  79.         emailtitle = atom.entries[i].title
  80.         # show only first few words if title is too long
  81.         if len(emailtitle.split()) > _maxwords:
  82.             emailtitle = ' '.join(emailtitle.split()[:_maxwords])
  83.            
  84. #        print "^fg(%s) from %s" % (_calmcolor,emailtitle, atom.entries[i].author)
  85.    
  86. if __name__ == "__main__":
  87.     feed = auth()  
  88.     showmail(feed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement