__init__.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import threading
  2. import email_mailgun
  3. import todo_wunderlist
  4. import input_sources
  5. import output
  6. import current_time
  7. import help
  8. import echo
  9. def _get_services():
  10. services = {
  11. 'email': email_mailgun.Email(),
  12. 'food': todo_wunderlist.Wunderlist(True, 'food'),
  13. 'todo': todo_wunderlist.Wunderlist(False),
  14. 'time': current_time.CurrentTime('Europe/Dublin'),
  15. 'echo': echo.Echo(),
  16. #'play': music.Music(),
  17. }
  18. services['help'] = help.Help(services)
  19. return services
  20. def launch_services(interrupted):
  21. services = _get_services()
  22. for s in services.values():
  23. if not s.initialized:
  24. t = threading.Thread(target=s.init)
  25. t.start()
  26. output.tts('Ready.')
  27. while not interrupted():
  28. t = input_sources.get_token(1)
  29. if t is not None and t in services and services[t].initialized:
  30. output.debug('Entering %s' % t)
  31. services[t].call()
  32. elif t == 'quit':
  33. return
  34. elif t is not None:
  35. output.failure('"%s" is not a valid service.' % t)