Skip to content

Commit

Permalink
fix datetime parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Apr 25, 2024
1 parent 4d9d886 commit a9c979e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
import os.path

import datetime
import requests
from ovos_bus_client.session import Session, SessionManager
from ovos_config import Configuration
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit a9c979e

Please sign in to comment.