__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. 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. Available services: %s.' % ', '.join(sorted(_services.keys())))
  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. _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)