Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: drop lingua-franca #71

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import geocoder
import pytz
from lingua_franca.format import nice_date, nice_duration, nice_time, date_time_format
from lingua_franca.parse import extract_datetime, fuzzy_match, normalize
from ovos_bus_client.message import Message
from ovos_date_parser import nice_time, extract_datetime, nice_date, nice_duration, date_time_format, nice_weekday, \
nice_month
from ovos_utils import classproperty
from ovos_utils.log import LOG
from ovos_utils.parse import fuzzy_match
from ovos_utils.process_utils import RuntimeRequirements
from ovos_utils.time import now_local, get_next_leap_year
from ovos_utterance_normalizer import UtteranceNormalizerPlugin
from ovos_workshop.decorators import intent_handler
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.skills import OVOSSkill
Expand Down Expand Up @@ -240,27 +242,6 @@ def get_display_date(self, location: str = None,
elif fmt == 'DMY':
return dt.strftime("%d/%-m/%-Y")

def nice_weekday(self, dt: datetime.datetime) -> str:
"""Get localized weekday name."""
# TODO - move to lingua-franca
if self.lang in date_time_format.lang_config.keys():
localized_day_names = list(
date_time_format.lang_config[self.lang]['weekday'].values())
weekday = localized_day_names[dt.weekday()]
else:
weekday = dt.strftime("%A")
return weekday.capitalize()

def nice_month(self, dt: datetime.datetime) -> str:
"""Get localized month name."""
# TODO - move to lingua-franca
if self.lang in date_time_format.lang_config.keys():
localized_month_names = date_time_format.lang_config[self.lang]['month']
month = localized_month_names[str(int(dt.strftime("%m")))]
else:
month = dt.strftime("%B")
return month.capitalize()

######################################################################
# Time queries / display
def speak_time(self, dialog: str, location: str = None):
Expand Down Expand Up @@ -297,8 +278,10 @@ def handle_current_time_simple(self, message):

@intent_handler("what.time.will.it.be.intent")
def handle_query_future_time(self, message):
utt = normalize(message.data.get('utterance', "").lower())
dt, utt = extract_datetime(utt) or (None, None)
normalizer = UtteranceNormalizerPlugin.get_normalizer(self.lang)
utt = normalizer.normalize(message.data["utterance"])

dt, utt = extract_datetime(utt, lang=self.lang) or (None, None)
if not dt:
self.handle_query_time(message)
return
Expand Down Expand Up @@ -453,9 +436,9 @@ def show_date_gui(self, dt: datetime.datetime, location: str):
self.gui.clear()
self.gui['location_string'] = str(location)
self.gui['date_string'] = self.get_display_date(anchor_date=dt)
self.gui['weekday_string'] = self.nice_weekday(dt)
self.gui['weekday_string'] = nice_weekday(dt, lang=self.lang)
self.gui['day_string'] = dt.strftime('%d')
self.gui['month_string'] = self.nice_month(dt)
self.gui['month_string'] = nice_month(dt, lang=self.lang)
self.gui['year_string'] = dt.strftime("%Y")
if self.date_format == 'MDY':
self.gui['daymonth_string'] = f"{self.gui['month_string']} {self.gui['day_string']}"
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ tzlocal>=1.3
timezonefinder~=5.2
geocoder~=1.38
ovos-utils>=0.0.38
ovos-workshop>=0.0.16,<3.0.0
ovos-workshop>=0.0.16,<3.0.0
ovos-date-parser>=0.0.1,<1.0.0
ovos-utterance-normalizer>=0.0.1,<1.0.0
Loading