Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- """
- Checks Gmail for unread mails by parsing the unread mail feed.
- Requires python-feedparser. Set _USER and _PASSWD before using.
- """
- import urllib
- import feedparser
- _URL = 'https://mail.google.com/mail/feed/atom/' # Gmail feed url
- _USER = '' # Username
- _PASSWD = '' # Password
- # Colors
- _GREEN = '\033[1;32m'
- _YELLOW = '\033[1;33m'
- _RESET = '\033[0;0m'
- class GmailOpener(urllib.FancyURLopener):
- """
- Child class of urllib.FancyURLopener. Overrides the default
- prompt_user_passwd() method and returns (_USER, _PASSWD) instead.
- """
- def prompt_user_passwd(self, host, realm):
- return _USER, _PASSWD
- def readMail():
- """
- Function to authenticate and read mail.
- """
- opener = GmailOpener()
- f = opener.open(_URL)
- feed = feedparser.parse(f)
- unread = feed['feed']['fullcount']
- print ('You have' + _GREEN + ' (' + _YELLOW + unread + _GREEN + ') ' +
- _RESET + 'unread mails.\n')
- if unread != '0':
- for mail in feed.entries:
- print '* ' + mail.author + ' : ' + mail.title + '\n'
- if __name__ == '__main__':
- readMail()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement