Hardware Reference
In-Depth Information
Setup of the e-mail alerts in the
fountain
In this task, we will review seing up e-mail alerts from Gmail accounts. We can blink an
LED (as shown in this step) or flash the RGB LED strip (this has to be executed by the reader)
when an e-mail of a specific category is received (for example, work e-mail).
Prepare for lift off
We will get started by installing the python-feedparser tool. Google provides a read-only
inbox feed and we will make use of the feedparser module to determine whether we
received any new e-mails.
sudo apt-get install python-feedparser
Engage thrusters
1. In order to log in and parse through the e-mail feed, we get started by imporing the
feedparser module:
import sys
import feedparser
2. We will define the variables, including the Gmail username and password (changed
to generic names below) along with the funcion that retrieves all unread e-mails.
Refer to the following example:
In this example, we are just retrieving the count of any new unread e-mails.
It is possible to parse and identify e-mails with specific labels. We will leave
that to the reader. For more information, refer to https://developers.
google.com/gmail/gmail_inbox_feed .
newEmail=""
username="username@gmail.com"
password="password"
proto="https://"
server="mail.google.com"
path="/gmail/feed/atom"
def mail():
email = int(feedparser.parse(proto+username+":"+password+"@"+ser
ver+path)["feed"]["fullcount"])
return email
 
Search WWH ::




Custom Search