From a9c979e8033ffc0793aa59b384f44dc4e4ea4db2 Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 25 Apr 2024 03:53:39 +0100 Subject: [PATCH] fix datetime parsing --- __init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index c3b902b..52fc000 100644 --- a/__init__.py +++ b/__init__.py @@ -12,6 +12,7 @@ # import os.path +import datetime import requests from ovos_bus_client.session import Session, SessionManager from ovos_config import Configuration @@ -26,6 +27,7 @@ from padacioso import IntentContainer from padacioso.bracket_expansion import expand_parentheses from quebra_frases import sentence_tokenize +from lingua_franca.format import nice_date class DuckDuckGoSolver(QuestionSolver): @@ -131,10 +133,14 @@ def get_infobox(self, query, context=None): for entry in infodict.get("content", []): k = entry["label"].lower().strip() v = entry["value"] - if k in time_keys: - infobox[k] = v["time"] # TODO - datetime object - else: - infobox[k] = v + try: + if k in time_keys and "time" in v: + dt = datetime.datetime.strptime(v["time"], "+%Y-%m-%dT%H:%M:%SZ") + infobox[k] = nice_date(dt, lang=self.default_lang) + else: + infobox[k] = v + except: # probably a LF error + continue return infobox, related_topics def extract_and_search(self, query, context=None): @@ -359,6 +365,11 @@ def stop_session(self, sess): if __name__ == "__main__": + from ovos_utils.fakebus import FakeBus + from ovos_config.locale import setup_locale + setup_locale() + s = DuckDuckGoSkill(bus=FakeBus(), skill_id="fake.duck") + s.CQS_match_query_phrase("who is Stephen Hawking") d = DuckDuckGoSolver()