| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import threading
- import email_mailgun
- import todo_wunderlist
- import input_sources
- import output
- import current_time
- import services.help
- import echo
- import duckduckgo_answers
- import music
- def _get_services():
- res = {
- 'email': email_mailgun.Email(),
- 'food': todo_wunderlist.Wunderlist(True, 'food'),
- 'todo': todo_wunderlist.Wunderlist(False),
- 'time': current_time.CurrentTime('Europe/Dublin'),
- 'echo': echo.Echo(),
- 'duck': duckduckgo_answers.DuckDuckGo(),
- 'play': music.Music(),
- }
- res['help'] = services.help.Help(res)
- return res
- def launch_services(interrupted):
- _services = _get_services()
- for s in _services.values():
- if not s.initialized:
- t = threading.Thread(target=s.init)
- t.start()
- output.text('Ready.')
- while not interrupted():
- input_sources.PREFERRED_PHRASES = _services.keys() + ['quit']
- t = input_sources.get_token(1)
- if t is not None and t in _services and _services[t].initialized:
- output.debug('Entering %s' % t)
- _services[t].call()
- elif t == 'quit':
- return
- elif t is not None:
- output.failure('"%s" is not a valid service.' % t)
|