diff --git a/__init__.py b/__init__.py index 3af97449e0e723379104889926b86fc62a7554ca..54562f2c986954dfc192a7a4faa766b427cb4782 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,5 @@ +from subprocess import CalledProcessError, check_output + from mycroft import MycroftSkill, intent_file_handler @@ -7,13 +9,25 @@ class Wtf(MycroftSkill): @intent_file_handler('wtf.intent') def handle_wtf(self, message): - acronym = message.data.get('acronym') - definitions = '' + acronym = message.data.get('acronym').upper() + + try: + output = check_output(['wtf', acronym]).decode('utf-8') + except CalledProcessError: + self.speak_dialog('gee', data={ + 'acronym': acronym + }) + else: + definitions = [] + for line in output.split('\n'): + line = line.replace('%s:' % acronym, '').strip() + if line: + definitions.append(line) - self.speak_dialog('wtf', data={ - 'definitions': definitions, - 'acronym': acronym - }) + self.speak_dialog('wtf', data={ + 'definitions': ', '.join(definitions), + 'acronym': acronym + }) def create_skill(): diff --git a/locale/en-us/gee.dialog b/locale/en-us/gee.dialog new file mode 100644 index 0000000000000000000000000000000000000000..7b1a26acd0b518412414366cf03bacef108256b5 --- /dev/null +++ b/locale/en-us/gee.dialog @@ -0,0 +1 @@ +Gee, I don’t know what "{acronym}" means. diff --git a/locale/en-us/wtf.dialog b/locale/en-us/wtf.dialog index 8e0ac2049faa3b1c543a76df4db72ad7107e00d5..acfcc5cd49519b4e722375d6c37b7539503ae85a 100644 --- a/locale/en-us/wtf.dialog +++ b/locale/en-us/wtf.dialog @@ -1 +1 @@ -{{acronym}} means {{definitions}} +{acronym} means {definitions} diff --git a/locale/en-us/wtf.intent b/locale/en-us/wtf.intent index e47c0cc25b0559e12c9da47ee981d5d1f7ee3bad..adc367e4b014d3efd61d0402d13d1036e96d6114 100644 --- a/locale/en-us/wtf.intent +++ b/locale/en-us/wtf.intent @@ -1,2 +1 @@ -Wtf is {{acronym}} -What the fuck is {{acronym}} +( wtf | what the fuck ) is {acronym}