From 687fba91ccf1e119d27041b3a7898263e8d6e296 Mon Sep 17 00:00:00 2001
From: Dominik George <nik@naturalnet.de>
Date: Sat, 15 Feb 2020 00:47:16 +0100
Subject: [PATCH] Implement funcionality

---
 __init__.py             | 26 ++++++++++++++++++++------
 locale/en-us/gee.dialog |  1 +
 locale/en-us/wtf.dialog |  2 +-
 locale/en-us/wtf.intent |  3 +--
 4 files changed, 23 insertions(+), 9 deletions(-)
 create mode 100644 locale/en-us/gee.dialog

diff --git a/__init__.py b/__init__.py
index 3af9744..54562f2 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 0000000..7b1a26a
--- /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 8e0ac20..acfcc5c 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 e47c0cc..adc367e 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}
-- 
GitLab