本文整理匯總了Python中semantic.dates.DateService.parseDay方法的典型用法代碼示例。如果您正苦於以下問題:Python DateService.parseDay方法的具體用法?Python DateService.parseDay怎麽用?Python DateService.parseDay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類semantic.dates.DateService
的用法示例。
在下文中一共展示了DateService.parseDay方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle
# 需要導入模塊: from semantic.dates import DateService [as 別名]
# 或者: from semantic.dates.DateService import parseDay [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)
"""
if not profile['location']:
mic.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.parseDay(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
forecast = getForecast(profile)
output = None
for entry in forecast:
try:
date_desc = entry['title'].split()[0].strip().lower()
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)
mic.say(output)
else:
mic.say(
"I'm sorry. I can't see that far ahead.")