__init__.py 851 B

12345678910111213141516171819202122232425262728293031
  1. import threading
  2. import email_mailgun
  3. import todo_wunderlist
  4. import input_sources
  5. import output
  6. def _get_services():
  7. return {
  8. 'email': email_mailgun.Email(),
  9. 'food': todo_wunderlist.Wunderlist(True, 'food'),
  10. 'todo': todo_wunderlist.Wunderlist(False),
  11. #'play': music.Music(),
  12. }
  13. def launch_services(interrupted):
  14. services = _get_services()
  15. for s in services.values():
  16. if not s.initialized:
  17. t = threading.Thread(target=s.init)
  18. t.start()
  19. output.text('Ready.')
  20. while not interrupted():
  21. t = input_sources.get_token(5)
  22. if t is not None and t in services and services[t].initialized:
  23. output.debug('Entering %s' % t)
  24. services[t].call()
  25. elif t is not None:
  26. output.failure('"%s" is not a valid service.' % t)