View previous topic :: View next topic |
Author |
Message |
Gherald Veteran
Joined: 23 Aug 2004 Posts: 1399 Location: CLUAConsole
|
Posted: Wed Jan 19, 2005 12:47 am Post subject: Gmail Notifier + Thinkpad extension |
|
|
For some time I have been trying to find a gmail notifier that would be effective regardless of whether I was using the console, X, or some other fullscreen app. Failing to find even a decent CLI notifier, I wrote my own: gmaild
First order of business:
If the portage version of libgmail is still 0.0.8 or earlier, you will need to get the latest from CVS and put it in /usr/lib/python2.3/site-packages/
Now as root create a file /usr/bin/gmaild as shown below, chmod it 700, and replace USERNAME-HERE and PASSWORD-HERE with your gmail login.
Code: | #!/usr/bin/python
import libgmail
import sys,os,time
def notify(subject):
os.popen('/usr/bin/thinklight') #notification command
def mainloop():
ga = libgmail.GmailAccount("USERNAME-HERE", "PASSWORD-HERE")
ga.login()
folder = ga.getMessagesByFolder('inbox')
id = folder._threads[0].id
while 1:
time.sleep(120)
folder = ga.getMessagesByFolder('inbox')
thread = folder._threads[0]
if thread.id != id:
if thread.subject[0:3]=="<b>": #html bold means unread
notify(thread.subject)
id = thread.id
while 1:
try:
mainloop()
except KeyboardInterrupt:
sys.exit()
except Exception:
time.sleep(120) |
Non-thinkpad owners will need to replace the command '/usr/bin/thinklight' with an alternative such as 'wall' or 'festival'.
Next create the startup script /etc/init.d/gmaild as shown below and chmod it 755
Code: | #!/sbin/runscript
depend() {
use net
}
start() {
ebegin "Starting gmaild"
start-stop-daemon --start --quiet --background --pidfile /var/run/gmaild.pid --make-pidfile --exec /usr/bin/gmaild
eend $?
}
stop() {
ebegin "Stopping gmaild"
start-stop-daemon --stop --quiet --pidfile /var/run/gmaild.pid --name gmaild
eend $?
} |
Thinkpad owners with a working thinklight can create /usr/bin/thinklight as shown below and chmod it 755.
Code: | #!/bin/bash
function flash {
cd /proc/acpi/ibm
STATE=$(grep status light | sed 's/status:\t*//')
for i in {1,2,3}; do
echo on > light
sleep .3
echo off > light
sleep .3
done
echo $STATE >> light
}
flash |
Start the service:
Code: | /etc/init.d/gmaild start
rc-update add gmaild default |
Now send yourself a test message and wait patiently for less than 2 minutes
Last edited by Gherald on Thu Mar 24, 2005 1:41 am; edited 8 times in total |
|
Back to top |
|
|
Khan Tux's lil' helper
Joined: 19 Feb 2003 Posts: 96
|
Posted: Thu Jan 20, 2005 5:47 pm Post subject: Sweet! |
|
|
This is pure genius! Thanks for this cool little notifier. My T42p really "shines" now |
|
Back to top |
|
|
allucid Veteran
Joined: 02 Nov 2002 Posts: 1314 Location: atlanta
|
Posted: Thu Jan 20, 2005 6:12 pm Post subject: |
|
|
wait...this turns on the keyboard light at the top of the lcd? what if the light is already on? |
|
Back to top |
|
|
piquadrat Guru
Joined: 18 Feb 2003 Posts: 301 Location: Switzerland
|
Posted: Thu Jan 20, 2005 7:34 pm Post subject: |
|
|
allucid wrote: | what if the light is already on? |
The thinklight script from freeix makes the light blink |
|
Back to top |
|
|
Gherald Veteran
Joined: 23 Aug 2004 Posts: 1399 Location: CLUAConsole
|
Posted: Thu Jan 20, 2005 9:46 pm Post subject: |
|
|
Yes, the light blinks then gets set to its previous state.
It appears google broke libgmail again, including the CVS version...I've had to fallback to the gmail firefox extension.
I hope libgmail get things sorted out soon. |
|
Back to top |
|
|
nafre Guru
Joined: 27 Dec 2003 Posts: 388
|
|
Back to top |
|
|
Gherald Veteran
Joined: 23 Aug 2004 Posts: 1399 Location: CLUAConsole
|
Posted: Fri Jan 21, 2005 5:49 am Post subject: |
|
|
nafre: Yes, that is great.
Here is the libgmail error I am getting:
Code: | # /usr/bin/gmaild
Traceback (most recent call last):
File "/usr/bin/gmaild", line 11, in ?
folder = ga.getMessagesByFolder('inbox')
File "/usr/bin/libgmail.py", line 408, in getMessagesByFolder
return self._parseThreadSearch(folderName, allPages = allPages)
File "/usr/bin/libgmail.py", line 362, in _parseThreadSearch
items = self._parseSearchResult(searchType, start, **kwargs)
File "/usr/bin/libgmail.py", line 347, in _parseSearchResult
return self._parsePage(_buildURL(**params))
File "/usr/bin/libgmail.py", line 318, in _parsePage
items = _parsePage(self._retrievePage(urlOrRequest))
File "/usr/bin/libgmail.py", line 116, in _parsePage
if itemsDict[D_VERSION] != js_version and not versionWarned:
KeyError: 'v' |
If it doesn't get fixed soon, I am thinking of writing a version that uses pop.gmail.com |
|
Back to top |
|
|
nafre Guru
Joined: 27 Dec 2003 Posts: 388
|
Posted: Fri Jan 21, 2005 11:50 pm Post subject: |
|
|
yes!
i can not test this version! _________________ Nome- Felipe
Nick- Nafre
Idade- 25
Salvador - Bahia - Brasil |
|
Back to top |
|
|
Tamnir n00b
Joined: 11 Mar 2003 Posts: 27
|
Posted: Thu Jan 27, 2005 5:56 am Post subject: |
|
|
ping (just to watch this topic) |
|
Back to top |
|
|
allucid Veteran
Joined: 02 Nov 2002 Posts: 1314 Location: atlanta
|
Posted: Thu Jan 27, 2005 6:22 am Post subject: |
|
|
Tamnir wrote: | ping (just to watch this topic) |
...below each thread is a "Watch this topic for replies" link. |
|
Back to top |
|
|
Gherald Veteran
Joined: 23 Aug 2004 Posts: 1399 Location: CLUAConsole
|
Posted: Mon Jan 31, 2005 1:13 am Post subject: |
|
|
The fix is in CVS, go here to get the latest version and put it in /usr/lib/python2.3/site-packages/
Last edited by Gherald on Mon Jan 31, 2005 7:11 am; edited 2 times in total |
|
Back to top |
|
|
Tamnir n00b
Joined: 11 Mar 2003 Posts: 27
|
Posted: Mon Jan 31, 2005 3:48 am Post subject: [OFFTOPIC] watch this topic |
|
|
[OFFTOPIC]
Thanks allucid. I'll go run and hide in shame now
I did look for that link though, thinking there must be a way to start watching a topic without having to post in it, but didn't find it. Not that I am blind: I don't post often, so most of the time I don't bother logging in and just browse anonymously. And then, that link does not appear, whereas the "new topic" and "post reply" do show up and just ask you to log in before you can continue. That is a design bug in phpBB I guess. For consistency, the "watch this topic" link should behave the same way. |
|
Back to top |
|
|
Gherald Veteran
Joined: 23 Aug 2004 Posts: 1399 Location: CLUAConsole
|
Posted: Thu Mar 24, 2005 1:59 am Post subject: |
|
|
I added exception handling so the daemon doesn't give up on socket and urllib errors...
crishchun has a perl script that can be used to display detailed gmail information in torsmo or the like.
Milez has another, much niftier and more complex python script that makes use of Gmail Atom feeds. |
|
Back to top |
|
|
Lowspirit Apprentice
Joined: 31 Jul 2002 Posts: 258 Location: Northern Sweden
|
Posted: Fri Mar 25, 2005 1:50 am Post subject: |
|
|
Thanks for the tip, love this one, though I don't have a thinkpad I had to think outside the box on how to get notified...
/usr/bin/eject
Edit: The idea was good but I'm getting nothing, my gmaild is silent as a mouse and I have messages in my inbox, no errors either, no diff using portage nor cvs, what am I doing wrong? _________________ Gentoo | AMD X2 3800+ 2GB RAM | Kernel 2.6.30 . ReiserFS . CFQ . GCC4.3.3 | Firefox 3.5 | Gnome 2.26 w/ Compiz-Fusion
"Penguins are the only fish that can fly" |
|
Back to top |
|
|
Gherald Veteran
Joined: 23 Aug 2004 Posts: 1399 Location: CLUAConsole
|
Posted: Fri Mar 25, 2005 4:00 am Post subject: |
|
|
eject... nice one! Finally a use for one of those ten old 24x drives I've got stacked in my closet
To see what errors you're getting, remove the lines:
Code: | except Exception:
time.sleep(120) |
and run /usr/bin/gmaild manually from a root prompt.
Make sure you have libgmail from CVS. |
|
Back to top |
|
|
iarwain Apprentice
Joined: 25 Sep 2003 Posts: 253
|
Posted: Sat Mar 18, 2006 12:51 pm Post subject: |
|
|
Hi,
This script looks great, really cute and useful... but it doesn't work for me. It's strange because /usr/bin/gmaild says nothing, no output. Even deleting those two lines mentioned by Gherald. I have libgmail.py from CVS. Does it still work for you? Any ideas?
Thank you! |
|
Back to top |
|
|
iarwain Apprentice
Joined: 25 Sep 2003 Posts: 253
|
Posted: Thu Apr 13, 2006 12:52 pm Post subject: |
|
|
Hi again. After playing with the code I'm having a problem with this portion:
Code: | thread = folder._threads[0]
if thread.id != id:
if thread.subject[0:3]=="<b>": #html bold means unread
notify(thread.subject)
id = thread.id |
I was never notified about new messages. I don't understand the "if thread.id != id" part. So I have modified it this way:
Code: | #!/usr/bin/python
import libgmail
import sys, os, time
def notify(subject):
os.popen('/usr/bin/thinklight') #notification command
ga = libgmail.GmailAccount("USERNAME@gmail.com", "PASSWORD")
ga.login()
def mainloop():
while 1:
time.sleep(120)
folder = ga.getMessagesByFolder('inbox')
thread = folder._threads[0]
for thread in folder:
if thread.subject[0:3]=="<b>": #html bold means unread
notify(thread.subject)
while 1:
try:
mainloop()
except KeyboardInterrupt:
sys.exit()
except Exception:
time.sleep(120) |
Now it works for me. I don't know why it didn't with Gherald's initial code.
By the way, would it possible to store the password shadowed in another file instead of as clear text?
Thank you. |
|
Back to top |
|
|
|