usr bin env python coding utf-8 import urllib import feedparser _url h

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import feedparser
_url = "https://mail.google.com/gmail/feed/atom"
_pwd = "password"
_username = "username"
class GmailRSSOpener(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
return (_username, _pwd)
def auth():
opener = GmailRSSOpener()
f = opener.open(_url)
feed = f.read()
return feed
def getUnreadMsgCount(feed):
atom = feedparser.parse(feed)
newmails = len(atom.entries)
return newmails
if __name__ == "__main__":
print getUnreadMsgCount(auth())