You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arvydas Juskevicius edited this page Aug 1, 2013
·
1 revision
This example shows how to blink BlinkStick when there is new mail in GMail account.
Change username and password variables below to your account details. When you run this script and there is new mail in your inbox, BlinkStick will blink once in red color.
importurllib# For BasicHTTPAuthenticationimportfeedparser# For parsing the feedfromblinkstickimportblinkstickusername="username"password='password'#No need to edit anything below this line_URL="https://mail.google.com/gmail/feed/atom"bstick=blinkstick.find_first()
#This overriden class will automatically supply username and password for atom URLclassmy_opener (urllib.FancyURLopener):
# Overridedefget_user_passwd(self, host, realm, clear_cache=0):
return (username, password)
defauth():
'''The method to do HTTPBasicAuthentication'''opener=my_opener()
f=opener.open(_URL)
feed=f.read()
returnfeeddefreadmail(feed):
'''Parse the Atom feed and print a summary'''atom=feedparser.parse(feed)
print""printatom.feed.titleprint"You have %s new mails"%len(atom.entries)
ifbstickisnotNoneandlen(atom.entries) >0:
bstick.blink(name="red")
if__name__=="__main__":
f=auth() # Do auth and then get the feedreadmail(f) # Let the feed be chewed by feedparser