__init__.py 1.2 KB

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