-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify-read.py
executable file
·78 lines (57 loc) · 2.34 KB
/
notify-read.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
import array, os, time, json
import gi.repository.GLib
import dbus
from dbus.mainloop.glib import DBusGMainLoop
def init_log():
file_checks = os.path.expanduser('~') + "/.cache/notifications.log"
file_exists = os.path.exists(file_checks)
if not file_exists:
os.system("touch " + file_checks)
def notifications(bus, message):
c = 0; msg = []
for arg in message.get_args_list():
if "dbus" not in str(arg) and str(arg) != "0" and str(arg) != "-1" and str(arg) != "" and int(len(str(arg))) > 6 :
msg.append(str(arg))
c+=1
dat = str(int(time.time()))
if len(msg) == 4:
#DEALS WITH ICONS AND IMAGES
out = dat + "::" + msg[0].lower() + "::" + msg[2] + "::" + msg[3]
data_new = {"timestamp":dat,
"application":msg[0].lower(),
"title": msg[2],
"description":msg[3]}
elif len(msg) == 3:
out = dat + "::" + msg[0].lower() + "::" + msg[1] + "::" + msg[2]
data_new = {"timestamp":dat,
"application":msg[0].lower(),
"title": msg[1],
"description":msg[2]}
elif len(msg) == 2:
out = dat + "::" + msg[0].lower() + "::" + msg[1]
data_new = {"timestamp":dat,
"application":msg[0].lower(),
"title": msg[1],
"description":""}
else:
out = dat + "::" + msg[0].lower()
data_new = {"timestamp":dat,
"application":"generic",
"title": "",
"description":""}
print(out)
os.system("echo " + out + " >> " + os.path.expanduser('~') + "/.cache/notifications.log")
filename = str(os.path.expanduser('~') + "/.cache/notifications.json")
with open(filename,'r+') as file:
file_data = json.load(file)
file_data["notifications"].append(data_new)
file.seek(0)
json.dump(file_data, file, indent = 4)
init_log()
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
bus.add_message_filter(notifications)
mainloop = gi.repository.GLib.MainLoop()
mainloop.run()