Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Gmail Notifier + Thinkpad extension
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Wed Jan 19, 2005 12:47 am    Post subject: Gmail Notifier + Thinkpad extension Reply with quote

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:
Code:
emerge -a libgmail

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
View user's profile Send private message
Khan
Tux's lil' helper
Tux's lil' helper


Joined: 19 Feb 2003
Posts: 96

PostPosted: Thu Jan 20, 2005 5:47 pm    Post subject: Sweet! Reply with quote

This is pure genius! Thanks for this cool little notifier. My T42p really "shines" now :D
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Thu Jan 20, 2005 6:12 pm    Post subject: Reply with quote

wait...this turns on the keyboard light at the top of the lcd? what if the light is already on?
Back to top
View user's profile Send private message
piquadrat
Guru
Guru


Joined: 18 Feb 2003
Posts: 301
Location: Switzerland

PostPosted: Thu Jan 20, 2005 7:34 pm    Post subject: Reply with quote

allucid wrote:
what if the light is already on?


The thinklight script from freeix makes the light blink
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Thu Jan 20, 2005 9:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
nafre
Guru
Guru


Joined: 27 Dec 2003
Posts: 388

PostPosted: Fri Jan 21, 2005 1:50 am    Post subject: Reply with quote

https://forums.gentoo.org/viewtopic.php?t=282913

I translation for portuguese in brazilian (PT_BR).

OK?
_________________
Nome- Felipe
Nick- Nafre
Idade- 25
Salvador - Bahia - Brasil
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Fri Jan 21, 2005 5:49 am    Post subject: Reply with quote

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
View user's profile Send private message
nafre
Guru
Guru


Joined: 27 Dec 2003
Posts: 388

PostPosted: Fri Jan 21, 2005 11:50 pm    Post subject: Reply with quote

yes!

i can not test this version!
_________________
Nome- Felipe
Nick- Nafre
Idade- 25
Salvador - Bahia - Brasil
Back to top
View user's profile Send private message
Tamnir
n00b
n00b


Joined: 11 Mar 2003
Posts: 27

PostPosted: Thu Jan 27, 2005 5:56 am    Post subject: Reply with quote

ping (just to watch this topic)
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Thu Jan 27, 2005 6:22 am    Post subject: Reply with quote

Tamnir wrote:
ping (just to watch this topic)

...below each thread is a "Watch this topic for replies" link.
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Mon Jan 31, 2005 1:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Tamnir
n00b
n00b


Joined: 11 Mar 2003
Posts: 27

PostPosted: Mon Jan 31, 2005 3:48 am    Post subject: [OFFTOPIC] watch this topic Reply with quote

[OFFTOPIC]

Thanks allucid. I'll go run and hide in shame now :oops:

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
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Thu Mar 24, 2005 1:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Lowspirit
Apprentice
Apprentice


Joined: 31 Jul 2002
Posts: 258
Location: Northern Sweden

PostPosted: Fri Mar 25, 2005 1:50 am    Post subject: Reply with quote

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
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Fri Mar 25, 2005 4:00 am    Post subject: Reply with quote

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
View user's profile Send private message
iarwain
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 253

PostPosted: Sat Mar 18, 2006 12:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
iarwain
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 253

PostPosted: Thu Apr 13, 2006 12:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum