def test_round_trip(self): fact = Fact.parse( "11:00 12:00 activity, with comma@category,, description, with comma #and #tags" ) dbus_fact = to_dbus_fact_json(fact) return_fact = from_dbus_fact_json(dbus_fact) self.assertEqual(return_fact, fact) dbus_fact = to_dbus_fact(fact) return_fact = from_dbus_fact(dbus_fact) self.assertEqual(return_fact, fact) fact = Fact.parse("11:00 activity") dbus_fact = to_dbus_fact_json(fact) return_fact = from_dbus_fact_json(dbus_fact) self.assertEqual(return_fact, fact) dbus_fact = to_dbus_fact(fact) return_fact = from_dbus_fact(dbus_fact) self.assertEqual(return_fact, fact) range, __ = dt.Range.parse("2020-01-19 11:00 - 2020-01-19 12:00") dbus_range = to_dbus_range(range) return_range = from_dbus_range(dbus_range) self.assertEqual(return_range, range)
def get_todays_facts(self): """returns facts of the current date, respecting hamster midnight hamster midnight is stored in gconf, and presented in minutes """ return [ from_dbus_fact_json(fact) for fact in self.conn.GetTodaysFactsJSON() ]
def get_facts(self, start, end=None, search_terms=""): """Returns facts for the time span matching the optional filter criteria. In search terms comma (",") translates to boolean OR and space (" ") to boolean AND. Filter is applied to tags, categories, activity names and description """ range = dt.Range.from_start_end(start, end) dbus_range = to_dbus_range(range) return [from_dbus_fact_json(fact) for fact in self.conn.GetFactsJSON(dbus_range, search_terms)]
def UpdateFactJSON(self, fact_id, dbus_fact): """Update fact. Args: fact_id (int): fact id in the database. dbus_fact (str): new fact content, in JSON format. Returns: int: new id (0 means failure) """ fact = from_dbus_fact_json(dbus_fact) return self.update_fact(fact_id, fact)
def AddFactJSON(self, dbus_fact): """Add fact given in JSON format. This is the preferred method if the fact fields are known separately, as activity, category, description and tags are passed "verbatim". Only datetimes are interpreted (2020-01-20: JSON does not know datetimes). Args: dbus_fact (str): fact in JSON format (cf. from_dbus_fact_json). Returns: fact id (int), 0 means failure. """ fact = from_dbus_fact_json(dbus_fact) return self.add_fact(fact)
def CheckFact(self, dbus_fact, dbus_default_day): """Check fact validity. Useful to determine in advance whether the fact can be included in the database. Args: dbus_fact (str): fact in JSON format (cf. AddFactJSON) Returns: success (boolean): True upon success. message (str): what's wrong. """ fact = from_dbus_fact_json(dbus_fact) dd = from_dbus_date(dbus_default_day) try: self.check_fact(fact, default_day=dd) success = True message = "" except FactError as error: success = False message = str(error) return success, message
def get_fact(self, id): """returns fact by it's ID""" return from_dbus_fact_json(self.conn.GetFactJSON(id))