[hamster-applet] example how to operate with dbus
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] example how to operate with dbus
- Date: Fri, 29 Jan 2010 16:17:31 +0000 (UTC)
commit 4e300c30b2994fc6953aac7b62155eb28f035311
Author: Toms Bauģis <toms baugis gmail com>
Date: Fri Jan 29 16:16:56 2010 +0000
example how to operate with dbus
contrib/export_today.py | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/contrib/export_today.py b/contrib/export_today.py
new file mode 100755
index 0000000..c45280f
--- /dev/null
+++ b/contrib/export_today.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# - coding: utf-8 -
+# Copyright (C) 2010 Toms Bauģis <toms.baugis at gmail.com>
+
+import dbus
+import datetime as dt
+
+HAMSTER_DBUS_PATH = "/org/gnome/Hamster"
+HAMSTER_DBUS_IFACE = "org.gnome.Hamster"
+
+
+
+if __name__ == "__main__":
+ bus = dbus.SessionBus()
+ obj = bus.get_object(HAMSTER_DBUS_IFACE, HAMSTER_DBUS_PATH)
+ hamster = dbus.Interface(obj, "org.gnome.Hamster")
+
+
+ facts = []
+ for fact in hamster.GetFacts(0, 0):
+ # run through the facts and convert them to python types so it's easier to operate with
+ res = {}
+ for key in ['name', 'category', 'description']:
+ res[key] = str(fact[key])
+
+ for key in ['start_time', 'end_time', 'date']:
+ res[key] = dt.datetime.utcfromtimestamp(fact[key]) if fact[key] else None
+
+ res['delta'] = dt.timedelta(days = fact['delta'] / (60 * 60 * 24),
+ seconds = fact['delta'] % (60 * 60 * 24))
+
+ res['tags'] = [str(tag) for tag in fact['tags']] if fact['tags'] else []
+
+ facts.append(res)
+
+ print "here are your facts!", facts
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]