Pārlūkot izejas kodu

#17 current time service

Martin 10 gadi atpakaļ
vecāks
revīzija
0b9b5bd00a

+ 3 - 1
voice_control/services/__init__.py

@@ -3,12 +3,14 @@ import email_mailgun
 import todo_wunderlist
 import input_sources
 import output
+import current_time
 
 def _get_services():
     return {
         'email': email_mailgun.Email(),
         'food': todo_wunderlist.Wunderlist(True, 'food'),
         'todo': todo_wunderlist.Wunderlist(False),
+        'time': current_time.CurrentTime('Europe/Dublin'),
         #'play': music.Music(),
     }
 
@@ -23,7 +25,7 @@ def launch_services(interrupted):
     output.text('Ready.')
 
     while not interrupted():
-        t = input_sources.get_token(5)
+        t = input_sources.get_token(1)
         if t is not None and t in services and services[t].initialized:
             output.debug('Entering %s' % t)
             services[t].call()

+ 16 - 0
voice_control/services/current_time.py

@@ -0,0 +1,16 @@
+import arrow
+import base
+import output
+
+class CurrentTime(base.BaseService):
+    def __init__(self, tz):
+        self.tz = tz
+    
+    def call(self):
+        now = arrow.now(self.tz)
+        h, m = now.hour, now.minute
+        if m < 10:
+            output.tts('%i oh %i' % (h, m))
+        else:
+            output.tts('%i %i' % (h, m))
+