from mycroft.skills.common_query_skill import CommonQuerySkill, CQSMatchLevel
# Dict mapping python members to their age and whether they're alive or dead
'eric idle': (77,'alive'),
'michael palin': (77, 'alive'),
'john cleese': (80, 'alive'),
'graham chapman': (48, 'dead'),
'terry gilliam': (79, 'alive'),
'terry jones': (77, 'dead')
def python_in_utt(utterance):
"""Find a monty python member in the utterance.
utterance (str): Sentence to check for Monty Python members
(str) name of Monty Python member or None
if key in utterance.lower():
# Return the found python
class PythonAgeSkill(CommonQuerySkill):
"""A Skill for checking the age of the python crew."""
def format_answer(self, python):
"""Create string with answer for the specified "python" person."""
age, status = PYTHONS[python]
return self.dialog_renderer.render('age_alive',
{'person': python, 'age': age})
return self.dialog_renderer.render('age_dead',
{'person': python, 'age': age})
def CQS_match_query_phrase(self, utt):
"""Check the utterance if it is a question we can answer.
Returns: tuple (input utterance, match level, response sentence, extra)
# Check if this is an age query
age_query = self.voc_match(utt, 'age')
# Check if a monty python member is mentioned
python = full_python_in_utt(utt)
# If this is an age query and a monty python member is mentioned the
return (utt, CQSMatchLevel.CATEGORY, self.format_answer(python))