2

I have put together a simple time difference python script with whatever I know and it works fine with Python 2.7.3. The script finds the time difference and then sends a desktop notification in Ubuntu using python-notify.

$ cat timediff.py 
import sys
import pynotify
import datetime

now = datetime.datetime.now().replace(microsecond=0)
then = datetime.datetime(2012,11,5,8,0,0)

diff = then - now

hours = (diff.seconds) / 3600
minutes = (diff.seconds - hours * 3600) / 60
seconds = (diff.seconds  - (hours * 3600 + minutes * 60))

def sendmessage(title, message):
    pynotify.init("image")
    notice = pynotify.Notification(title,message,"/usr/share/icons/gnome/48x48/status/important.png").show()
    return notice
sendmessage("Time remaining to exam","%s days, %s hours, %s minutes and %s seconds."% (diff.days,hours,minutes,seconds))

However, it seems to fail if I run it with Python 3.2.3. It seems like there is no python-notify module for Python 3.2.

$ python3.2 timediff.py 
Traceback (most recent call last):
  File "timediff.py", line 2, in <module>
    import pynotify
ImportError: No module named pynotify

Is it possible to use python-notify with Python3 somehow or am I going to have to stick with Python 2.7 until the bindings are ported for Python 3.2?

I found a mailing list dated April 2010 which suggests that pynotify may not be Python3 compatible. Has there been improvements on that regard at least?

jokerdino
  • 2,047
  • 1
  • 25
  • 31

1 Answers1

4

I haven't tried it, but here is a pynotify replacement.

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
  • in ubuntu, I suggest using this installation method. includes some examples. https://askubuntu.com/a/616996/378854 – phil294 Apr 26 '17 at 22:18