Monday, September 09, 2013

Gmail alert on Pi with PiGlow

I use quite a few notifiers to keep me aware of incoming emails on my Gmail system.
On my Mac, I use Google Notifier in the upper panel as well as the Google Mail Checker and Mail Checker Plus for Google Mail as extensions in Google Chrome.

I also have a mail checker in Conky which I use in all my computers running Linux. And this includes my Raspberry Pi's.
(Yes, I know the apostrophe is both unnecessary and grammatically incorrect. However, without it the last term in the plural form of the little computer seems to refer to a bodily effluent).

Great, so I should never miss an incoming email?
Well, not necessarily.
A lot of times I'm working or reading at my desk without a computer which may therefore all be in sleep mode.
As a result, I don't see the Gmail alerts.

Well, the PiGlow add-on board provides a great and very spectacular solution for my RPi.

How to set up the PiGlow is fully explained here.

Next I wrote two bash scripts to provide the LED sequences I wanted for my email alerts.

Here they are:

Text File: new_mail

#!/bin/bash 
for i in {1..10} 
do 
sudo piglow leg 0 25 
sudo piglow off 
sudo piglow leg 1 60 
sudo piglow off 
sudo piglow leg 2 100 
sudo piglow off 
done 
for j in {1..5} 
do 
sudo piglow all 100 
sleep 0.25 
sudo piglow off 
sleep 0.25 
done

 Text File: new_mail


          #!/bin/bash

          for i in {1..10}

         do
sudo piglow ring 1 25 
sudo piglow off 
sudo piglow ring 2 40 
sudo piglow off 
sudo piglow ring 3 55 
sudo piglow off 
sudo piglow ring 4 75 
sudo piglow off 
sudo piglow ring 5 100 
sudo piglow off 
sudo piglow ring 4 75 
sudo piglow off 
sudo piglow ring 3 55 
sudo piglow off 
sudo piglow ring 2 40 
sudo piglow off 
sudo piglow ring 1 25 
sudo piglow off 
done 
for j in {1..5} 
do 
sudo piglow leg 0 35 
sudo piglow off 
sudo piglow leg 1 70 
sudo piglow off 
sudo piglow leg 2 100 
sudo piglow off 
done

To use these scripts, they must be made executable by running the command
$ chmod +x new_mail

They can now be tested by moving to the directory where they are stored and running with the command (I stored them in my ~/Scripts which explains why I'm not using sudo)
$ ./new_mail
If all went well, these scripts may now be used to alert you to incoming emails.

I have referred before to the gmail_parser.py script by Baishampayan Ghose that works perfectly in Conky to update my unread email number.

I also mentioned in the previous post that I had updated this parser script to show the output in a different colour depending on the number of unread mails.

To get conky to alert me through my PiGlow of incoming mail just required me to further modify the gmail_parser.py script.
Below is the "heart" of the parser script that contains the changes:

def readmail(feed, maxlen): 

'''Parse the Atom feed and print a summary''' 

atom = feedparser.parse(feed) 

print '${color2} % s new email(s)\n' % (len(atom.entries)) 

elif len(atom.entries) == 1: 

print '${color3} %s new email(s)\n' % (len(atom.entries)) 

import subprocess 

subprocess.call("/home/paul/Scripts/new_mail", shell=True) 

else: 

print '${color4} %s new email(s)\n' % (len(atom.entries)) 

import subprocess 

subprocess.call("/home/paul/Scripts/new_mail2", shell=True)

The changes made to gmail_parser.py to enact the gmail alerts on the PiGlow are marked in blue.

And here's what the alert looks like (in a disappointingly unsharp video, but you'll get the idea):

video
 




No comments:

Post a Comment