当前位置: 首页>>代码示例>>Python>>正文


Python DateService.extractDate方法代码示例

本文整理汇总了Python中semantic.dates.DateService.extractDate方法的典型用法代码示例。如果您正苦于以下问题:Python DateService.extractDate方法的具体用法?Python DateService.extractDate怎么用?Python DateService.extractDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在semantic.dates.DateService的用法示例。


在下文中一共展示了DateService.extractDate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from semantic.dates import DateService [as 别名]
# 或者: from semantic.dates.DateService import extractDate [as 别名]
def handle(text, mic, profile):
    """
    Responds to user-input, typically speech text, with a summary of
    the relevant weather for the requested date (typically, weather
    information will not be available for days beyond tomorrow).

    Arguments:
        text -- user-input, typically transcribed speech
        mic -- used to interact with the user (for both input and output)
        profile -- contains information related to the user (e.g., phone
                   number)
    """
    try:
        weather_client = yweather.Client()
        weather = weather_client.fetch_weather(profile["location"]["id"], metric=True)

        tz = getTimezone(profile)
        service = DateService(tz=tz)
        date = service.extractDate(text)
        if not date:
            date = datetime.datetime.now(tz=tz)

        weekday = service.__daysOfWeek__[date.weekday()]

        if date.weekday() == datetime.datetime.now(tz=tz).weekday():
            mic.say(
                ("Today, %s at %s degrees with wind speed" + " of %.1f metres per second")
                % (code2desc(weather["condition"]), weather["condition"]["temp"], float(weather["wind"]["speed"]) / 3.6)
            )
            return

        elif date.weekday() == (datetime.datetime.now(tz=tz).weekday() + 1) % 7:
            date_keyword = "Tomorrow"
        else:
            date_keyword = "On " + weekday

        weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        for fore in weather["forecast"]:
            if weekdays[date.weekday()] == fore["day"]:
                mic.say(
                    ("%s, %s with temperatures raging" + " from %s to %s degrees")
                    % (date_keyword, code2desc(fore), fore["low"], fore["high"])
                )
                break
        else:
            mic.say("I'm sorry. I can't see that far ahead.")
    except:
        mic.say("I'm sorry. I can't see that far ahead.")
开发者ID:yannickulrich,项目名称:IRIS,代码行数:50,代码来源:Weather.py

示例2: compareDate

# 需要导入模块: from semantic.dates import DateService [as 别名]
# 或者: from semantic.dates.DateService import extractDate [as 别名]
 def compareDate(self, input, target):
     service = DateService()
     result = service.extractDate(input)
     self.assertEqual(result.month, target.month)
     self.assertEqual(result.day, target.day)
开发者ID:caje731,项目名称:semantic,代码行数:7,代码来源:testDates.py

示例3: compareTime

# 需要导入模块: from semantic.dates import DateService [as 别名]
# 或者: from semantic.dates.DateService import extractDate [as 别名]
 def compareTime(self, input, target):
     service = DateService()
     result = service.extractDate(input)
     self.assertEqual(result.hour, target.hour)
     self.assertEqual(result.minute, target.minute)
开发者ID:caje731,项目名称:semantic,代码行数:7,代码来源:testDates.py

示例4: compareDate

# 需要导入模块: from semantic.dates import DateService [as 别名]
# 或者: from semantic.dates.DateService import extractDate [as 别名]
 def compareDate(self, input, target):
     service = DateService()
     result = service.extractDate(input)
     self.assertEqual(target, result)
开发者ID:twizoo,项目名称:semantic,代码行数:6,代码来源:testDates.py


注:本文中的semantic.dates.DateService.extractDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。