本文整理汇总了Python中semantic.dates.DateService.extractDay方法的典型用法代码示例。如果您正苦于以下问题:Python DateService.extractDay方法的具体用法?Python DateService.extractDay怎么用?Python DateService.extractDay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semantic.dates.DateService
的用法示例。
在下文中一共展示了DateService.extractDay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from semantic.dates import DateService [as 别名]
# 或者: from semantic.dates.DateService import extractDay [as 别名]
def handle(text, speaker, requester, 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
speaker -- used to interact with the user (output)
requester -- used to interact with the user (input)
profile -- contains information related to the user (e.g., phone
number)
"""
forecast = None
if 'wmo_id' in profile:
forecast = get_forecast_by_wmo_id(str(profile['wmo_id']))
elif 'location' in profile:
forecast = get_forecast_by_name(str(profile['location']))
if not forecast:
speaker.clean_and_say("I'm sorry, I can't seem to access that information. Please " +
"make sure that you've set your location on the dashboard.")
return
tz = getTimezone(profile)
service = DateService(tz=tz)
date = service.extractDay(text)
if not date:
date = datetime.datetime.now(tz=tz)
weekday = service.__daysOfWeek__[date.weekday()]
if date.weekday() == datetime.datetime.now(tz=tz).weekday():
date_keyword = "Today"
elif date.weekday() == (
datetime.datetime.now(tz=tz).weekday() + 1) % 7:
date_keyword = "Tomorrow"
else:
date_keyword = "On " + weekday
output = None
for entry in forecast:
try:
date_desc = entry['title'].split()[0].strip().lower()
if date_desc == 'forecast':
# For global forecasts
date_desc = entry['title'].split()[2].strip().lower()
weather_desc = entry['summary']
elif date_desc == 'current':
# For first item of global forecasts
continue
else:
# US forecasts
weather_desc = entry['summary'].split('-')[1]
if weekday == date_desc:
output = date_keyword + \
", the weather will be " + weather_desc + "."
break
except:
continue
if output:
output = replaceAcronyms(output)
speaker.clean_and_say(output)
else:
speaker.clean_and_say(
"I'm sorry. I can't see that far ahead.")