forked from oscarfroberg/irssi-notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irssi-notify.py
executable file
·55 lines (45 loc) · 1.21 KB
/
irssi-notify.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#/usr/bin/env python
import os
import time
import subprocess
# the log file of the channel you want notifications for:
logfile = "/home/oscar/irclogs/freenode/#channel.log"
# messages from these screennames will be ignored (add as many as you like):
screennames = ['screenname', 'name_', 'screenie']
curtime = ""
logchanged = ""
def reset():
global logchanged
global curtime
logchanged = os.stat(logfile).st_mtime
curtime = os.stat(logfile).st_mtime
def displaynotification(lastline):
execlist = ['notify-send', lastline]
subprocess.call(execlist)
def readlastline():
f = open(logfile, 'rU')
lastline = f.readlines()[-1]
lastline = lastline[5:]
display = True
for i in screennames:
sn = "< " + i + ">"
if sn in lastline:
display = False
if display == True:
displaynotification(lastline)
def checklog():
global logchanged
global curtime
while curtime == logchanged:
logchanged = os.stat(logfile).st_mtime
time.sleep(0.5)
reset()
readlastline()
def launch():
reset()
print "irssi-notify is running"
while 1 == 1:
checklog()
time.sleep(0.01)
if __name__ == '__main__':
launch()