Permalink
Browse files

example how to operate with dbus

  • Loading branch information...
1 parent c604247 commit 4e300c30b2994fc6953aac7b62155eb28f035311 @tstriker tstriker committed Jan 29, 2010
Showing with 36 additions and 0 deletions.
  1. +36 −0 contrib/export_today.py
View
@@ -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

0 comments on commit 4e300c3

Please sign in to comment.