-
Notifications
You must be signed in to change notification settings - Fork 990
Expand file tree
/
Copy pathclock.py
More file actions
56 lines (45 loc) · 1.7 KB
/
Copy pathclock.py
File metadata and controls
56 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
import datetime
from jasper import app_utils
from jasper import plugin
class ClockPlugin(plugin.SpeechHandlerPlugin):
def get_phrases(self):
return [self.gettext("TIME")]
def init(self):
SpeechHandlerPlugin.init(self)
self._tti.ACTIONS = [('WHAT TIME IS IT',self.say_time)]
def handle(self, text, mic):
"""
Reports the current time based on the user's timezone.
Arguments:
text -- user-input, typically transcribed speech
mic -- used to interact with the user (for both input and output)
"""
tz = app_utils.get_timezone(self.profile)
now = datetime.datetime.now(tz=tz)
if now.minute == 0:
fmt = "It is {t:%l} {t:%P} right now."
else:
fmt = "It is {t:%l}:{t.minute} {t:%P} right now."
mic.say(self.gettext(fmt).format(t=now))
def say_time(self):
"""
Reports the current time based on the user's timezone.
Arguments:
text -- user-input, typically transcribed speech
mic -- used to interact with the user (for both input and output)
"""
tz = app_utils.get_timezone(self.profile)
now = datetime.datetime.now(tz=tz)
if now.minute == 0:
fmt = "It is {t:%l} {t:%P} right now."
else:
fmt = "It is {t:%l}:{t.minute} {t:%P} right now."
mic.say(self.gettext(fmt).format(t=now))
def is_valid(self, text):
"""
Returns True if input is related to the time.
Arguments:
text -- user-input, typically transcribed speech
"""
return any(p.lower() in text.lower() for p in self.get_phrases())