From 50a2a97af0d0593a63410fd6103d9e9acf80dc14 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sat, 10 Feb 2024 21:05:02 +0100 Subject: [PATCH] first commit --- src/clibard/clibard.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 src/clibard/clibard.py diff --git a/src/clibard/clibard.py b/src/clibard/clibard.py new file mode 100755 index 0000000..819af17 --- /dev/null +++ b/src/clibard/clibard.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +from enum import IntEnum +import datetime + +import dbus +import gi.repository.GLib +from dbus.mainloop.glib import DBusGMainLoop + +def receive(bus, notification): + # print(notification, flush = True) + # print("---------------------------------------------", flush = True) + # print("Member:", notification.get_member(), flush = True) + # print("Interface:", notification.get_interface(), flush = True) + + if notification.get_member() == "Notify" and notification.get_interface() == 'org.freedesktop.Notifications': + # print("Notification") + args = notification.get_args_list() + # print("Args list:", args, flush = True) + + app = str(args[0]) + replaces_id = int(args[1]) + # icon = str(args[2]) + summary = str(args[3]) + body = str(args[4]) + actions = args[5] + hints = dict(args[6]) + expire_timeout = int(args[7]) + + date = datetime.datetime.now() + urgency = {0: "low", 1: "normal", 2: "critical", None: "unknown"} + + print(f"[{date}][{app}]:\n\t{summary}\n\t« {body} »", flush=True) + + +if __name__ == "__main__": + 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(receive) + + mainloop = gi.repository.GLib.MainLoop() + mainloop.run() +