Skip to content

Instantly share code, notes, and snippets.

@Paaskehare
Created July 30, 2012 21:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Paaskehare/3210264 to your computer and use it in GitHub Desktop.
Save Paaskehare/3210264 to your computer and use it in GitHub Desktop.
Python3 Script for counting unread emails from gmail, useful for conky
#!/usr/bin/env python
# encoding: utf-8
from urllib.request import FancyURLopener
username = 'username'
password = 'superlongandhardpassword'
url = 'https://%s:%s@mail.google.com/mail/feed/atom' % (username, password)
opener = FancyURLopener()
page = opener.open(url)
contents = page.read().decode('utf-8')
ifrom = contents.index('<fullcount>') + 11
ito = contents.index('</fullcount>')
unread = contents[ifrom:ito]
print(unread)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment