__init__.py 1.2 KB

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