Page 2 of 3

Re: Prowl Gmail Python Script

Posted: Fri Oct 09, 2009 12:43 pm
by ccjensen
hey,

works great so far, but every time I delete the topmost email in my gmail inbox, I am sent a prowl notification about the "new" topmost email (ie the one who used to be the second newest), this happens independent of the "read" status of this item/email.

Let me know if there is any specific debugging I can do. Might take a look at the script myself over the weekend to see if I can figure it out.
Thanks for the script,
Chris

Re: Prowl Gmail Python Script

Posted: Fri Oct 09, 2009 3:06 pm
by chriscannon
@ccjensen Interesting, I've never experienced this because I never delete e-mail from my Gmail account. I'll take a look into it and get back to you.

If you figure out what the issue is, please keep me posted.

Re: Prowl Gmail Python Script

Posted: Fri Oct 09, 2009 5:17 pm
by ccjensen
Also, I just had it crash on me; here is the trace log from python:

Code: Select all

Traceback (most recent call last):
  File "./gprowl.py", line 278, in <module>
    main(sys.argv[1:])
  File "./gprowl.py", line 275, in main
    GmailIdleNotifier().start()
  File "./gprowl.py", line 163, in start
    self.fetchEmail(emailId)
  File "./gprowl.py", line 192, in fetchEmail
    date = self.formatDate(emailInfo).strip()
  File "./gprowl.py", line 217, in formatDate
    t = time.strptime(str(date[6:end]).strip(),"%a, %d %b %Y %H:%M:%S")
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/_strptime.py", line 454, in _strptime_time
    return _strptime(data_string, format)[0]
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/_strptime.py", line 325, in _strptime
    (data_string, format))
ValueError: time data 'Fri, 9 Oct 09 09:28:48' does not match format '%a, %d %b %Y %H:%M:%S'


Will see what I can figure out concerning the other bug.
Chris

Re: Prowl Gmail Python Script

Posted: Fri Oct 09, 2009 11:27 pm
by ccjensen
Before starting to look into the bug, I updated to the latest version of the script, and it seems you have fixed the error :)
So far, so good. I added this stuff:

Code: Select all

import syslog
syslog.openlog("Gprowl")
syslog.syslog(syslog.LOG_ALERT, "Starting Gprowl Notifier")

And replaced some of the other print statements so that I use launchd to launch gprowl in the background when my user logs in, and I can monitor the feedback from the scripts in the osx console :)

Re: Prowl Gmail Python Script

Posted: Sat Oct 10, 2009 10:15 am
by ccjensen
Edit: I didn't include the changes to the print statements, as that might have removed it's platform independence. If anyone wants the modified version, just let me know.

Edit2: I just realised that the script was marked as copyright, and has no open source license associated with it, so I probably aren't allowed to redistribute a modified version. I have removed the link to the attachment until the issue of license can be sorted out.

I spoke too soon, it wasn't fixed :)
I have created a possible fix, it seems to work well. I have attached the modified version of the script (had to add .txt extension for the forums to accept it).

I had to change the script a bit. It now only sends a notification if a new email arrives in the inbox, and it is marked as unread. This means that you won't get notifications for either read emails if you delete stuff from the inbox or if you have several new and delete the top one.

I don't expect anyone to use this, as I am the one who has special needs. I like to have a clean inbox, and stuff archived or deleted.

So far only tested by me, so other chris's script is quite likely more stable :)
Chris

Re: Prowl Gmail Python Script

Posted: Sun Oct 11, 2009 7:08 pm
by chriscannon
@ccjensen Thanks for your input and code. I like how you check whether the e-mail is seen or unseen using the "fetch ID flags" command. I'm currently incorporating that into the script right now and will have another release soon. Also, do not worry about the copyright, feel free to post whatever you want. I will remove the copyright in the next update as well. I will re-post to this thread once it is updated.

An unrelated issue I'm experiencing is that the script will just stop responding after some period of time. This may have to do with connection time outs. To get around this, I'm adding a default time out interval of 15 minutes, that restarts the main subprocess.

- Chris

Re: Prowl Gmail Python Script

Posted: Mon Oct 12, 2009 7:38 am
by ccjensen
Cool beans :)
I like how you have incorporated the changes! I ran v0.9.9 through my tests, and it fails if you move a "seen" message from another folder back into the inbox (ie it sends a notification, even though this is already a read message) if it has any other flags then just \Seen associated with it. I filed a bug on sourceforge, as I figured I have poluted this thread enough :)

Re: Prowl Gmail Python Script

Posted: Mon Nov 02, 2009 11:31 pm
by Steve
Does anyone know how to check a folder other than the INBOX? I've tried using label names in place of INBOX (p.stdin.write(". examine INBOX\n") but it doesn't seem to work. It should though, right? Or is there a better way?

Edit: For some reason it works now. maybe I was having a different problem with the script.

What is the best way to catch errors? I'm running this on my ddwrt equipped router, and I had to install python to get it running. (I've got no experience with python) Should there be some sort of log that shows errors? Will the script close if it errors? (if it is running, it's working?)

Re: Prowl Gmail Python Script

Posted: Tue Nov 03, 2009 3:02 am
by fubaya
I googled ddwrt and see that it's a linux based router. If you have access to a shell on it, you can run a script like this (kill the gmail script first):

Code: Select all

#! /bin/sh
while `true`
do
/path/to/gmailscript
echo "crashed `date`" >> /path/to/log
done
It's an infinite loop and putting the gmail script between do and done means the loop is stuck until the gmail script is killed or crashes, then it runs the echo command (which logs the crash) and restarts the loop, which restarts the gmail script, waits for it to die, echos, restarts etc. So if you want to stop it, kill the script.sh, not the gmail script. Run it in the background with the command: script.sh &

/path/to/log will look like this:
crashed Mon Oct 19 13:57:35 EDT 2009
crashed Sun Nov 1 20:02:20 EST 2009

Re: Prowl Gmail Python Script

Posted: Tue Nov 03, 2009 4:00 am
by Steve
thanks for the logging script, and sorry for not fully explaining ddwrt.

Now that I've got gprowl working, I can set it up to do what I've been needing. I'll push alerts for my work emails that I have automatically archived to a label in Gmail, on a schedule with a cron job, and only if i'm away from my desk. Thanks to chris for doing the hard part!

Re: Prowl Gmail Python Script

Posted: Tue Nov 10, 2009 12:26 am
by mbac
ccjensen wrote:hey,

works great so far, but every time I delete the topmost email in my gmail inbox, I am sent a prowl notification about the "new" topmost email (ie the one who used to be the second newest), this happens independent of the "read" status of this item/email.


Hi,

Is there a solution for the above problem? Also, my messages still come appear with the wrong encoding (URL-encoded?)…

Please let me know if I can help, but be informed that I can’t code at all! :)

Thanks for the script,
m

Re: Prowl Gmail Python Script

Posted: Tue Nov 10, 2009 9:29 am
by ccjensen
I haven't had time to work on this for a while, but i have a modified version that deals with this issue. Unfortunately, it seems prone to crash now. I will try and pick it up again this week and get back to you if I can get it stable.

Chris

Re: Prowl Gmail Python Script

Posted: Thu Nov 12, 2009 12:32 pm
by ccjensen
ok, so I've looked into the matter, and it seems my custom version does a multi-threading no-no. I am testing a fix now, and will get back to you if that fixes the issue.
I am curious though, as none of my changes really seem to have caused this issue. Is no one else experience crashes with chriscannon's newest version of the script? The crash I am experiencing is:

Code: Select all

Exception in thread Thread-9:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 726, in run
    self.function(*self.args, **self.kwargs)
  File "./gprowl.py", line 216, in keepAlive
    self.p.stdin.write("DONE\n")
IOError: [Errno 32] Broken pipe


I've haven't tested this, but it would seem to me that this would also occur with chriscannon's version…
It would help me debug to get some feedback if it happens with his version too.

Re: Prowl Gmail Python Script

Posted: Mon Nov 16, 2009 8:01 am
by ccjensen
I haven't been able to get it to crash again, so either I somehow fixed it, or it knows I am watching it… so the code is attached (same procedure as last time, remove .txt from filename). If someone gives it a shot, and gets the crash mentioned above, let me know and I will keep looking into a solution, when time permits. Or really if you have any other issues :)

Chris

Re: Prowl Gmail Python Script

Posted: Mon Nov 16, 2009 8:06 am
by mbac
Is this version expected to fix the excess notifications, as well)

Anyway, I'll try it ASAP and post back with th results…

Re: Prowl Gmail Python Script

Posted: Mon Nov 16, 2009 9:27 pm
by ccjensen
yea. Obviously I have really only tested it with how I use gmail, but I only get notifications once per new email (not repeated when cleaning up inbox). The version I attached above "finally" crashed again, so I am testing a workaround. This means I haven't been able to find the cause, but I might be able to treat the symptom :)

Re: Prowl Gmail Python Script

Posted: Mon Nov 16, 2009 9:32 pm
by mbac
After a few hours, it crashed for me as well.

I’ve set the script as a launchd daemon that would restart every 2 hours, but it looks like launchd hasn’t really been able to kill the crashed process. When I got back to the computer, I had 99% CPU usage by the “Python” process.

Re: Prowl Gmail Python Script

Posted: Tue Nov 17, 2009 10:33 am
by ccjensen
Find attached my "fixed" version. It's a horrible fix, but it works. It catches the error that causes the program to crash, kills the previous process and starts a new one. Same procedure as last time, just some shallow testing been done

Re: Prowl Gmail Python Script

Posted: Fri Nov 27, 2009 7:33 pm
by rakkitoo
ccjensen wrote:Find attached my "fixed" version. It's a horrible fix, but it works. It catches the error that causes the program to crash, kills the previous process and starts a new one. Same procedure as last time, just some shallow testing been done



MY GOD! it works. The newest script works like charm. Im using it on my ubuntu OS. Thank you!

Re: Prowl Gmail Python Script

Posted: Fri Nov 27, 2009 11:53 pm
by mbac
Works fine in my limited testing.

Any idea how to fix the raw ISO-8859-1 encoding in message previews? As it is, non-ASCII characters in ISO-encoded emails look like this: =93synonymous=94 for “synonymous” and so on…

Thanks a lot for your effort!