Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Morse Code Gmail Notifier
#!/usr/bin/env python
"""
Morse_Gmail.py
m0xpd
December 2012
"""
import feedparser, time, sys
import RPi.GPIO as GPIO
""" Dictionary for Morse Characters... """
morse={'a':'01','b':'1000','c':'1010','d':'100','e':'0','f':'0010','g':'110',
'h':'0000','i':'00','j':'0111','k':'101','l':'0100','m':'11',
'n':'10','o':'111','p':'0110','q':'1101','r':'010','s':'000','t':'1',
'u':'001','v':'0001','w':'011','x':'1001','y':'1011','z':'1100',
'0':'11111','1':'01111','2':'00111','3':'00011','4':'00001',
'5':'00000','6':'10000','7':'11000','8':'11100','9':'11110',
'.':'010101',',':'110011','?':'001100','/':'10010','@':'011010',' ':'','(':'',')':''}
# Adjust Morse Speed by changing DitLength ...
DitLength=0.1 # (seconds)
DahLength=3*DitLength
# Set Up the GPIO...
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, False)
# a few function definitions...
def SendDit(Length):
""" Sends a Dit..."""
KeyDown(Length)
Last_Element="dit"
return Last_Element
def SendDah(Length):
""" Sends a Dah..."""
KeyDown(Length)
Last_Element="dah"
return Last_Element
def SendSpace(Length):
""" Wait for inter-element space..."""
time.sleep(Length)
return
def KeyDown(Length):
""" Keys the TX """
# set the output to Key Down...
GPIO.output(11, True)
time.sleep(Length)
# clear the output ...
GPIO.output(11, False)
return
# Insert your Gmail account details here...
USERNAME="xxx"
PASSWORD="xxx"
# Main Operating Loop...
while True:
response=feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")
unread_count=int(response["feed"]["fullcount"])
for i in range (0,unread_count):
name=response["items"][i].author
first_name=name[0:name.find(" ")]
for j in range (0,unread_count):
full_name=response["items"][j].author
name=full_name[0:full_name.find(" ")]
for i in range(0,len(name)):
morse_character=morse[name[i].lower()]
for element in range(0,len(morse_character)):
if morse_character[element]=="0":
junk=SendDit(DitLength)
SendSpace(DitLength)
else:
junk=SendDah(DahLength)
SendSpace(DitLength)
SendSpace(DahLength)
time.sleep(1)
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.