Skip to content

Commit

Permalink
Removed dependency on any one libnotify client
Browse files Browse the repository at this point in the history
The problem was when using python2 or python3,
there were a lot of problems when the said modules
for notification weren't supported by either of the
python version.

This commit fixes this problem, by importing the
appropriate module based on the python version
used.

This changes a way of running the script. You should
now run this script as:

python scorer.py
  • Loading branch information
Anubhav committed Mar 25, 2015
1 parent 96cbd78 commit 7cc129a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions scorer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
#!/usr/bin/env python3

from sys import version_info
import requests
from bs4 import BeautifulSoup
from gi.repository import Notify
if version_info.major is 2:
import pynotify
notifyModule = "pynotify"
if version_info.major is 3:
try:
from gi.Repository import Notify
notifyModule = "Notify"
except ImportError:
import notify2
notifyModule = "notify2"
from time import sleep


def sendmessage(title, message):
Notify.init("Scorer")
Notify.Notification.new(title, message, "dialog-information").show()
if notifyModule is "pynotify":
pynotify.init("Scorer")
pynotify.Notification(title, message, "dialog-information").show()
elif notifyModule is "Notify":
Notify.init("Scorer")
Notify.Notification.new(title, message, "dialog-information").show()
else:
notify2.init("Scorer")
notify2.Notification(title, message, "dialog-information").show()


url, match, score, interrupted = "http://static.cricinfo.com/rss/livescores.xml", 0, "", False
Expand Down

0 comments on commit 7cc129a

Please sign in to comment.