Created
February 4, 2013 21:50
-
-
Save kimondo/4710034 to your computer and use it in GitHub Desktop.
email to LEDborg script for Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imaplib | |
import email | |
#connect to gmail | |
mail = imaplib.IMAP4_SSL('imap.gmail.com') | |
mail.login('[email protected]','your_password') | |
mail.select('inbox') | |
mail.list() | |
typ, data = mail.search(None, 'ALL') | |
for num in data[0].split(): | |
typ, data = mail.fetch(num, '(RFC822)') | |
typ, data = mail.search(None, 'All') | |
ids = data[0] | |
id_list = ids.split() | |
# get most recent email id | |
latest_email_id = int( id_list[-1] ) | |
for i in range( latest_email_id, latest_email_id-1, -1): | |
typ, data = mail.fetch( i, '(RFC822)') | |
for response_part in data: | |
if isinstance(response_part, tuple): | |
msg = email.message_from_string(response_part[1]) | |
varSubject = msg['subject'] | |
varFrom = msg['from'] | |
varFrom = varFrom.replace('<','') | |
varFrom = varFrom.replace('>','') | |
if len( varSubject ) >35: | |
varSubject = varSubject[0:32] ='...' | |
#print the subject to test | |
print varSubject | |
#output the subject to the ledborg | |
LedBorg = open('/dev/ledborg', 'w') | |
LedBorg.write(varsubject) | |
del LedBorg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment