Stinky_F00t

gmail.py

Sep 26th, 2012
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import urllib.request
  2. from xml.etree import ElementTree as etree
  3.  
  4. # Enter your username and password below within quotes below, in place of ****.
  5. # Set up authentication for gmail
  6. auth_handler = urllib.request.HTTPBasicAuthHandler()
  7. auth_handler.add_password(realm='New mail feed',
  8. uri='https://mail.google.com/',
  9. user= 'usuário',
  10. passwd= 'senha')
  11. opener = urllib.request.build_opener(auth_handler)
  12. # ...and install it globally so it can be used with urlopen.
  13. urllib.request.install_opener(opener)
  14.  
  15. gmail = 'https://mail.google.com/gmail/feed/atom'
  16. NS = '{http://purl.org/atom/ns#}'
  17. with urllib.request.urlopen(gmail) as source:
  18. tree = etree.parse(source)
  19. fullcount = tree.find(NS + 'fullcount').text
  20. print(fullcount + ' new')
Advertisement
Add Comment
Please, Sign In to add comment