Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import urllib.request
  4.  
  5. email = 'your email'
  6. password = 'your password'
  7.  
  8. # Set up authentication for gmail
  9. auth_handler = urllib.request.HTTPBasicAuthHandler()
  10. auth_handler.add_password(realm='mail.google.com',
  11. uri='https://mail.google.com/',
  12. user=email,
  13. passwd=password)
  14. opener = urllib.request.build_opener(auth_handler)
  15. # ...and install it globally so it can be used with urlopen.
  16. urllib.request.install_opener(opener)
  17.  
  18. gmailurl = 'https://mail.google.com/gmail/feed/atom'
  19. with urllib.request.urlopen(gmailurl) as page:
  20. contents = page.read().decode('utf-8')
  21.  
  22. ifrom = contents.index('<fullcount>') + 11
  23. ito = contents.index('</fullcount>')
  24.  
  25. fullcount = contents[ifrom:ito]
  26.  
  27. print('{} new emails'.format(fullcount))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement