當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。