Created
January 8, 2012 21:57
-
-
Save willprice/1579856 to your computer and use it in GitHub Desktop.
Python Gmail Checker
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
#!/usr/bin/python2 | |
# Author: Will Price | |
# Date: Jan 2011 | |
# Import statements: | |
# - Feedparser - needed to extract mailcount | |
# - Serial - needed to send command to Arduino | |
# - Time - waiting for gmail to be read | |
import feedparser, serial, time | |
# Variables | |
checkPeriod = 60 # Time between check in seconds | |
username = "username" | |
password = "pass" | |
label = " " #Label of folder to check no. of unread messages | |
# Define 'msgCount' function, returns number of unread messages (CREDIT TO: Tom Paton) | |
def msgCount(uid, pwd, filter): | |
inbox = feedparser.parse("https://%s:%s@gmail.google.com/gmail/feed/atom%s" % (uid, pwd, filter)) | |
return len(inbox["entries"]) | |
# Loop | |
while True: | |
# Serial port setup | |
com = serial.Serial("/dev/ttyUSB0",9600,timeout=0.25) | |
msgs = msgCount(username, password, label) | |
if (msgs > 0): # If number of unread messages is greater than 0, then tell the arduino | |
com.write("%c" % (msgs) ) | |
# print "You have %d messages to read" % msgs # For debugging purposes | |
com.close() | |
while (msgs > 0): | |
msgs = msgCount(username, password, label) | |
time.sleep(10) | |
com = serial.Serial("/dev/ttyUSB0",9600,timeout=0.25) | |
com.write("%c" % 0) | |
# print "Inbox is empty" # For debugging purposes | |
com.close() | |
time.sleep(checkPeriod) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment