__init__.py 975 B

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