__init__.py 1.0 KB

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