-
Notifications
You must be signed in to change notification settings - Fork 0
/
irssi-notifications.py
41 lines (32 loc) · 1.01 KB
/
irssi-notifications.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import dbus, gobject
from HTMLParser import HTMLParser
from dbus.mainloop.glib import DBusGMainLoop
import subprocess
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def get_data(self):
return ''.join(self.fed)
def notify(title, text, timeout):
timeout = str(timeout * 1000)
subprocess.check_call(['notify-send', title, text, '-t', timeout])
def cHTML(html):
h = MLStripper()
message = h.unescape(html)
h.feed(message)
return h.get_data()
def new_message(subject, message):
notify(subject, message, 500)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(new_message,
dbus_interface="org.irssi.Irssi",
signal_name="IrssiNotify",
path='/org/irssi/Irssi')
notify("Running", "Irssi Notifications", 5)
loop = gobject.MainLoop()
loop.run()