__init__.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. import duckduckgo_answers
  10. def _get_services():
  11. services = {
  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. services['help'] = help.Help(services)
  21. return services
  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. t = input_sources.get_token(1)
  31. if t is not None and t in services and services[t].initialized:
  32. output.debug('Entering %s' % t)
  33. services[t].call()
  34. elif t == 'quit':
  35. return
  36. elif t is not None:
  37. output.failure('"%s" is not a valid service.' % t)