Skip to content

Instantly share code, notes, and snippets.

@FredrikAugust
Created February 22, 2015 01:11
Show Gist options
  • Save FredrikAugust/e25b8d2f15549ad6bbfd to your computer and use it in GitHub Desktop.
Save FredrikAugust/e25b8d2f15549ad6bbfd to your computer and use it in GitHub Desktop.
Python Mail Checker
# Python GMail Checker
# Written by Fredrik A. Madsen-Malmo [@MrMadsenMalmo]
# Import modules
import os
import RPi.GPIO as GPIO
from time import sleep
import imaplib
# Clear the terminal function
def clearTerm():
os.system('cls' if os.name == 'nt' else 'clear')
# Clear terminal
clearTerm()
# Setup the RPi board
GPIO.setmode(GPIO.BOARD)
# Setup the pin which will light up
GPIO.setup(__, GPIO.OUT)
# Turn off warnings for GPIO
GPIO.setwarnings(False)
# Set the username and password
USERNAME = raw_input("Username: ")
PASSWORD = raw_input("Password: ")
while True:
# Clear terminal
clearTerm()
# Establish a connection with gmail
s = imaplib.IMAP4_SSL("imap.gmail.com")
# Login to the acc.
s.login((USERNAME + "@gmail.com"), PASSWORD)
# Select the server
s.select("inbox")
# Check how many unread messages there are and store it in a variable
unread = len(s.search(None, 'UnSeen')[1][0].split())
# If username and password are set
if unread == 1:
message = "You have " + str(unread) + " unread message."
GPIO.output(__, 1)
os.system("sudo ./speech.sh " + message)
clearTerm()
print(message)
elif unread > 1:
message = "You have " + str(unread) + " unread messages."
GPIO.output(__, 1)
os.system("sudo ./speech.sh " + message)
clearTerm()
print(message)
else:
GPIO.ouput(__, 0)
os.system("sudo ./speech.sh You have no unread mail.")
clearTerm()
print("You have no unread mail.")
sleep(60)
#!/bin/bash
say() { local IFS=+;/usr/bin/mplayer -ao alsa -quiet -noconsolecontrols "http://translate.google.com/translate_tts?tl=en&q=$*"; }
say $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment