diff --git a/README.md b/README.md index 6095f89f..7fc8945f 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ JARVIS is at your service [here](http://m.me/J.A.R.V.I.S.on.Messenger). Currentl `Are you there?` `tell me a joke` `iron man movie` -`define a superhero` +`define comfort` `wiki html` `anything you want book` `random quote` diff --git a/config.py b/config.py index 2c3c5c78..56293741 100644 --- a/config.py +++ b/config.py @@ -2,4 +2,5 @@ VERIFY_TOKEN = '' WIT_AI_ACCESS_TOKEN = 'IKJJJYYVR3X672DHFVS7U7C4L2MQSS2P' GOODREADS_ACCESS_TOKEN = '' +WORDS_API_KEY = '' JOKES_SOURCE_FILE = 'modules/src/jokes.json' diff --git a/modules/src/dictionary.py b/modules/src/dictionary.py index 0026db4c..b6849483 100644 --- a/modules/src/dictionary.py +++ b/modules/src/dictionary.py @@ -1,15 +1,20 @@ import requests +import config +import os from templates.text import TextTemplate +WORDS_API_KEY = os.environ.get('WORDS_API_KEY', config.WORDS_API_KEY) + def process(input, entities): output = {} try: word = entities['word'][0]['value'] - token = os.environ.get('WORDS_API_KEY') - r = requests.get('https://wordsapiv1.p.mashape.com/words/' + word + '/definitions', headers = {'X-Mashape-Key':token}) + r = requests.get('https://wordsapiv1.p.mashape.com/words/' + word + '/definitions', headers={ + 'X-Mashape-Key': WORDS_API_KEY + }) data = r.json() output['input'] = input - output['output'] = TextTemplate('Definition of ' + word + ':\n' + data['definitions']['definition']).get_message() + output['output'] = TextTemplate('Definition of ' + word + ':\n' + data['definitions'][0]['definition']).get_message() output['success'] = True except: output['success'] = False diff --git a/modules/src/help.py b/modules/src/help.py index 88adccc2..ae149c81 100644 --- a/modules/src/help.py +++ b/modules/src/help.py @@ -2,7 +2,7 @@ def process(input, entities=None): help = '''Hi there! I'm Jarvis, your personal assistant.\nTell me things like the following:\n - - define a superhero\n - iron man 2 movie plot\n - tell me a joke\n - wiki html\n - anything you want book\n - random quote\n - usd to eur rate\n + - define comfort\n - iron man 2 movie plot\n - tell me a joke\n - wiki html\n - anything you want book\n - random quote\n - usd to eur rate\n I'm always learning, so do come back and say hi from time to time!\nHave a nice day.''' output = { 'input': input, diff --git a/modules/tests/test_dictionary.py b/modules/tests/test_dictionary.py index 88983724..6f7115ff 100644 --- a/modules/tests/test_dictionary.py +++ b/modules/tests/test_dictionary.py @@ -1,7 +1,7 @@ import modules def test_dictionary(): - assert('dictionary' == modules.process_query('define a superhero')[0]) + assert('dictionary' == modules.process_query('define comfort')[0]) assert('dictionary' == modules.process_query('cloud definition')[0]) assert('dictionary' == modules.process_query('what does an accolade mean?')[0]) assert('dictionary' != modules.process_query('something random')[0])