From 9d57936dfc0662bd455e3716806f2c106835014d Mon Sep 17 00:00:00 2001 From: Zachary Williamson Date: Wed, 14 Jun 2017 19:30:46 -0500 Subject: [PATCH 1/4] Minor code cleaning, formatted error messages --- modules/src/anime.py | 11 +++++---- modules/src/book.py | 11 +++++---- modules/src/currency.py | 11 +++++---- modules/src/dictionary.py | 11 +++++---- modules/src/help.py | 51 ++++++++++++++++++++------------------- modules/src/lyrics.py | 11 +++++---- modules/src/movie.py | 11 +++++---- modules/src/music.py | 12 +++++---- modules/src/time.py | 11 +++++---- modules/src/url.py | 11 +++++---- modules/src/video.py | 11 +++++---- modules/src/weather.py | 11 +++++---- modules/src/wiki.py | 11 +++++---- 13 files changed, 99 insertions(+), 85 deletions(-) diff --git a/modules/src/anime.py b/modules/src/anime.py index 330360af..fa2585bc 100644 --- a/modules/src/anime.py +++ b/modules/src/anime.py @@ -27,11 +27,12 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any anime matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - Death Note anime' - error_message += '\n - Dragon ball super anime status' - error_message += '\n - What is the anime rating of One Punch Man?' + error_message = """\ + I couldn't find any anime matching your query. + Please ask me something else, like: + - Death Note anime + - Dragon ball super anime status + - What is the anime rating of One Punch Man?""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/book.py b/modules/src/book.py index c7904081..a0590795 100644 --- a/modules/src/book.py +++ b/modules/src/book.py @@ -37,11 +37,12 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any book matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - book timeline' - error_message += '\n - harry potter book plot' - error_message += '\n - little women book rating' + error_message = """\ + I couldn't find any book matching your query. + Please ask me something else, like: + - book timeline + - harry potter book plot + - little women book rating""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/currency.py b/modules/src/currency.py index ad2e35f1..aabdad00 100644 --- a/modules/src/currency.py +++ b/modules/src/currency.py @@ -20,11 +20,12 @@ def process(input, entities): output['output'] = TextTemplate(conversion_details).get_message() output['success'] = True except: - error_message = 'I couldn\'t convert between those currencies.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - HKD to USD' - error_message += '\n - USD to EUR rate' - error_message += '\n - how much is 100 USD to INR' + error_message = """\ + I couldn't convert between those currencies. + Please ask me something else, like: + - HKD to USD + - USD to EUR rate + - how much is 100 USD to INR""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/dictionary.py b/modules/src/dictionary.py index c2c29f58..8b847aab 100644 --- a/modules/src/dictionary.py +++ b/modules/src/dictionary.py @@ -19,11 +19,12 @@ def process(input, entities): output['output'] = TextTemplate('Definition of ' + word + ':\n' + data['definitions'][0]['definition']).get_message() output['success'] = True except: - error_message = 'I couldn\'t find that definition.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - define comfort' - error_message += '\n - cloud definition' - error_message += '\n - what does an accolade mean?' + error_message = """\ + I couldn't find that definition. + Please ask me something else, like: + - define comfort + - cloud definition + - what does an accolade mean?""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/help.py b/modules/src/help.py index 1912cad0..e158a6fe 100644 --- a/modules/src/help.py +++ b/modules/src/help.py @@ -1,35 +1,36 @@ from templates.text import TextTemplate def process(input, entities=None): - help = 'Hi there! I\'m Jarvis, your personal assistant.' - if entities is not None: + helper = 'Hi there! I\'m Jarvis, your personal assistant.\n' + if entities: if 'sender' in entities and 'first_name' in entities['sender']: - sender_name = entities['sender']['first_name'] - help = help.replace('there', sender_name) - help += '\n\nYou can tell me things like:' - help += '\n - define comfort' - help += '\n - iron man 2 movie plot' - help += '\n - tell me a joke/quote/fact' - help += '\n - wiki html' - help += '\n - anything you want book' - help += '\n - usd to eur rate' - help += '\n - death note anime' - help += '\n - time in seattle' - help += '\n - songs by linkin park' - help += '\n - shorten google.com' - help += '\n - weather in london' - help += '\n - videos of sia' - help += '\n - flip a coin' - help += '\n - roll a die' - help += '\n - show a random xkcd comic' - help += '\n - latest news' - help += '\n - paradise lyrics' - help += '\n\nI\'m always learning, so do come back and say hi from time to time!' - help += '\nHave a nice day. :)' + helper = helper.replace('there', entities['sender']['first_name']) + helper += """ + You can tell me things like: + - define comfort + - iron man 2 movie plot + - tell me a joke/quote/fact + - wiki html + - anything you want book + - usd to eur rate + - death note anime + - time in seattle + - songs by linkin park + - shorten google.com + - weather in london + - videos of sia + - flip a coin + - roll a die + - show a random xkcd comic + - latest news + - paradise lyrics + + I'm always learning, so do come back and say hi from time to time! + Have a nice day. :)""" output = { 'input': input, - 'output': TextTemplate(help).get_message(), + 'output': TextTemplate(helper).get_message(), 'success': True } return output diff --git a/modules/src/lyrics.py b/modules/src/lyrics.py index a428bca1..0bc47031 100644 --- a/modules/src/lyrics.py +++ b/modules/src/lyrics.py @@ -51,11 +51,12 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any lyrics matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - paradise lyrics' - error_message += '\n - lyrics of the song hall of fame' - error_message += '\n - What are the lyrics to see you again?' + error_message = """\ + I couldn't find any lyrics matching your query. + Please ask me something else, like: + - paradise lyrics + - lyrics of the song hall of fame + - What are the lyrics to see you again?""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/movie.py b/modules/src/movie.py index 62db4a9d..40bdd6cd 100644 --- a/modules/src/movie.py +++ b/modules/src/movie.py @@ -17,11 +17,12 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find that movie.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - batman movie' - error_message += '\n - iron man 2 movie plot' - error_message += '\n - What is the rating of happyness movie?' + error_message = """\ + I couldn't find that movie. + Please ask me something else, like: + - batman movie + - iron man 2 movie plot + - What is the rating of happiness movie?""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/music.py b/modules/src/music.py index 00763226..02601b39 100644 --- a/modules/src/music.py +++ b/modules/src/music.py @@ -30,11 +30,13 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any music matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - hymn for the weekend song' - error_message += '\n - linkin park songs' - error_message += '\n - play hotel california' + error_message = """\ + I couldn't find any music matching your query. + Please ask me something else, like: + - hymn for the weekend song + - linkin park songs + - play hotel california""" + output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/time.py b/modules/src/time.py index 00ed2fe7..919fa052 100644 --- a/modules/src/time.py +++ b/modules/src/time.py @@ -19,11 +19,12 @@ def process(input, entities): output['output'] = TextTemplate('Location: ' + location_data[0]['display_name'] + '\nTime: ' + time + ' ' + time_data['abbreviation']).get_message() output['success'] = True except: - error_message = 'I couldn\'t get the time at the location you specified.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - time in new york' - error_message += '\n - india time' - error_message += '\n - time at paris' + error_message = """\ + I couldn't get the time at the location you specified. + Please ask me something else, like: + - time in new york + - india time + - time at paris""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/url.py b/modules/src/url.py index 728266e0..ab6e493a 100644 --- a/modules/src/url.py +++ b/modules/src/url.py @@ -31,11 +31,12 @@ def process(input, entities): output['output'] = TextTemplate(response).get_message() output['success'] = True except: - error_message = 'I couldn\'t perform that action.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - shorten google.com' - error_message += '\n - give me a short version of bing.com' - error_message += '\n - expand http://goo.gl/7aqe' + error_message = """\ + I couldn't perform that action. + Please ask me something else, like: + - shorten google.com + - give me a short version of bing.com + - expand http://goo.gl/7aqe""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/video.py b/modules/src/video.py index c236378c..5f2a9fec 100644 --- a/modules/src/video.py +++ b/modules/src/video.py @@ -28,11 +28,12 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any videos matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - sia videos' - error_message += '\n - videos by eminem' - error_message += '\n - video coldplay' + error_message = """\ + I couldn't find any videos matching your query. + Please ask me something else, like: + - sia videos + - videos by eminem + - video coldplay""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/weather.py b/modules/src/weather.py index 0856258c..3bd31dbb 100644 --- a/modules/src/weather.py +++ b/modules/src/weather.py @@ -19,11 +19,12 @@ def process(input, entities): output['output'] = TextTemplate('Location: ' + location_data[0]['display_name'] + '\nWeather: ' + weather_data['weather'][0]['description'] + '\nTemperature: ' + str(weather_data['main']['temp']) + ' ' + degree_sign + 'C / ' + str(temperature_in_fahrenheit) + ' ' + degree_sign + 'F\n- Info provided by OpenWeatherMap').get_message() output['success'] = True except: - error_message = 'I couldn\'t get the weather info you asked for.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - tell me the weather in London' - error_message += '\n - weather Delhi' - error_message += '\n - What\'s the weather in Texas?' + error_message = """\ + I couldn't get the weather info you asked for. + Please ask me something else, like: + - tell me the weather in London + - weather Delhi + - What's the weather in Texas?""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/wiki.py b/modules/src/wiki.py index af197509..656a848c 100644 --- a/modules/src/wiki.py +++ b/modules/src/wiki.py @@ -45,11 +45,12 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any wikipedia results matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - wikipedia barack' - error_message += '\n - html wiki' - error_message += '\n - who is sachin tendulkar' + error_message = """\ + I couldn't find any wikipedia results matching your query. + Please ask me something else, like: + - wikipedia barack + - html wiki + - who is sachin tendulkar""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output From 2f2d8c8c24c75ea2277c96c16bb53d62b94ebc6b Mon Sep 17 00:00:00 2001 From: Zachary Williamson Date: Sat, 24 Jun 2017 12:21:36 -0500 Subject: [PATCH 2/4] Added error_msg module to handle error formatting for current and future modules. --- modules/src/anime.py | 8 ++----- modules/src/book.py | 8 ++----- modules/src/currency.py | 8 ++----- modules/src/dictionary.py | 8 ++----- modules/src/error_msg.py | 50 +++++++++++++++++++++++++++++++++++++++ modules/src/lyrics.py | 8 ++----- modules/src/movie.py | 8 ++----- modules/src/request.py | 6 ++--- modules/src/time.py | 8 ++----- modules/src/weather.py | 8 ++----- modules/src/wiki.py | 8 ++----- 11 files changed, 71 insertions(+), 57 deletions(-) create mode 100644 modules/src/error_msg.py diff --git a/modules/src/anime.py b/modules/src/anime.py index fa2585bc..2d90ca1e 100644 --- a/modules/src/anime.py +++ b/modules/src/anime.py @@ -1,6 +1,7 @@ import requests import requests_cache from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_ANIME def process(input, entities): output = {} @@ -27,12 +28,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = """\ - I couldn't find any anime matching your query. - Please ask me something else, like: - - Death Note anime - - Dragon ball super anime status - - What is the anime rating of One Punch Man?""" + error_message = QUERY_ERROR.format('anime') + EXAMPLE_ANIME output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/book.py b/modules/src/book.py index a0590795..3a1392f5 100644 --- a/modules/src/book.py +++ b/modules/src/book.py @@ -5,6 +5,7 @@ from html2text import html2text from xml.etree import ElementTree from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_BOOKS GOODREADS_ACCESS_TOKEN = os.environ.get('GOODREADS_ACCESS_TOKEN', config.GOODREADS_ACCESS_TOKEN) @@ -37,12 +38,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = """\ - I couldn't find any book matching your query. - Please ask me something else, like: - - book timeline - - harry potter book plot - - little women book rating""" + error_message = QUERY_ERROR.format('books') + EXAMPLE_BOOKS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/currency.py b/modules/src/currency.py index aabdad00..f135cf64 100644 --- a/modules/src/currency.py +++ b/modules/src/currency.py @@ -1,5 +1,6 @@ import requests from templates.text import TextTemplate +from error_msg import CONVERT_ERROR, EXAMPLE_CONVERSIONS def process(input, entities): output = {} @@ -20,12 +21,7 @@ def process(input, entities): output['output'] = TextTemplate(conversion_details).get_message() output['success'] = True except: - error_message = """\ - I couldn't convert between those currencies. - Please ask me something else, like: - - HKD to USD - - USD to EUR rate - - how much is 100 USD to INR""" + error_message = CONVERT_ERROR.format('currencies') + EXAMPLE_CONVERSIONS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/dictionary.py b/modules/src/dictionary.py index 8b847aab..0992934e 100644 --- a/modules/src/dictionary.py +++ b/modules/src/dictionary.py @@ -3,6 +3,7 @@ import config import os from templates.text import TextTemplate +from error_msg import QUERY_ERROR, EXAMPLE_DEFINITIONS WORDS_API_KEY = os.environ.get('WORDS_API_KEY', config.WORDS_API_KEY) @@ -19,12 +20,7 @@ def process(input, entities): output['output'] = TextTemplate('Definition of ' + word + ':\n' + data['definitions'][0]['definition']).get_message() output['success'] = True except: - error_message = """\ - I couldn't find that definition. - Please ask me something else, like: - - define comfort - - cloud definition - - what does an accolade mean?""" + error_message = QUERY_ERROR.format('definition') + EXAMPLE_DEFINITIONS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/error_msg.py b/modules/src/error_msg.py new file mode 100644 index 00000000..70ea9cc0 --- /dev/null +++ b/modules/src/error_msg.py @@ -0,0 +1,50 @@ + +BASE_ERROR = "\nPlease ask me something else, like:" +QUERY_ERROR = "I couldn't find any {} matching your query." + BASE_ERROR +CONVERT_ERROR = "I couldn't convert between those {}." + BASE_ERROR +LOCATION_ERROR = "I couldn't get the {} at the location you specified." + BASE_ERROR + +EXAMPLE_ANIME = """ + - Death Note anime, + - Dragon ball super anime status, + - What is the anime rating of One Punch Man?""" + +EXAMPLE_BOOKS = """ + - book timeline + - harry potter book plot + - little women book rating""" + +EXAMPLE_CONVERSIONS = """ + - HKD to USD + - USD to EUR rate + - how much is 100 USD to INR""" + +EXAMPLE_DEFINITIONS = """ + - define comfort + - cloud definition + - what does an accolade mean?""" + +EXAMPLE_LYRICS = """ + - paradise lyrics + - lyrics of the song hall of fame + - What are the lyrics to see you again?""" + +EXAMPLE_MOVIES = """ + - batman movie + - iron man 2 movie plot + - What is the rating of happiness movie?""" + +EXAMPLE_TIME = """ + - time in new york + - india time + - time at paris""" + +EXAMPLE_WEATHER = """ + - tell me the weather in London + - weather Delhi + - What's the weather in Texas?""" + +EXAMPLE_WIKI = """ + - wikipedia barack + - html wiki + - who is sachin tendulkar""" \ No newline at end of file diff --git a/modules/src/lyrics.py b/modules/src/lyrics.py index 0bc47031..ac4828af 100644 --- a/modules/src/lyrics.py +++ b/modules/src/lyrics.py @@ -2,6 +2,7 @@ import config import os from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_LYRICS MUSIXMATCH_API_KEY = os.environ.get('MUSIXMATCH_API_KEY', config.MUSIXMATCH_API_KEY) @@ -51,12 +52,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = """\ - I couldn't find any lyrics matching your query. - Please ask me something else, like: - - paradise lyrics - - lyrics of the song hall of fame - - What are the lyrics to see you again?""" + error_message = QUERY_ERROR.format('lyrics') + EXAMPLE_LYRICS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/movie.py b/modules/src/movie.py index 40bdd6cd..5033f693 100644 --- a/modules/src/movie.py +++ b/modules/src/movie.py @@ -1,6 +1,7 @@ import requests import requests_cache from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_MOVIES def process(input, entities): output = {} @@ -17,12 +18,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = """\ - I couldn't find that movie. - Please ask me something else, like: - - batman movie - - iron man 2 movie plot - - What is the rating of happiness movie?""" + error_message = QUERY_ERROR.format('movie') + EXAMPLE_MOVIES output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/request.py b/modules/src/request.py index 78055300..7b6bf111 100644 --- a/modules/src/request.py +++ b/modules/src/request.py @@ -1,9 +1,9 @@ from templates.button import ButtonTemplate def process(input, entities=None): - request = 'Kindly use the following buttons to:' - request += '\n - Request a new feature, by including some sample queries and their expected results.' - request += '\n - Report a bug (I couldn\'t handle the query and/or gave unexpected results), by including your search query and the expected result.' + request = """Kindly use the following buttons to: + - Request a new feature, by including some sample queries and their expected results. + - Report a bug (I couldn't handle the query and/or gave unexpected results), by including your search query and the expected result.""" template = ButtonTemplate(request) template.add_web_url('File an Issue', 'https://github.com/swapagarwal/JARVIS-on-Messenger/issues/new') template.add_web_url('Chat with my Master', 'https://gitter.im/swapagarwal/JARVIS-on-Messenger') diff --git a/modules/src/time.py b/modules/src/time.py index 919fa052..03deb36f 100644 --- a/modules/src/time.py +++ b/modules/src/time.py @@ -3,6 +3,7 @@ import os from templates.text import TextTemplate from datetime import datetime +from error_msg import LOCATION_ERROR, EXAMPLE_TIME MAPQUEST_CONSUMER_KEY = os.environ.get('MAPQUEST_CONSUMER_KEY', config.MAPQUEST_CONSUMER_KEY) TIME_ZONE_DB_API_KEY = os.environ.get('TIME_ZONE_DB_API_KEY', config.TIME_ZONE_DB_API_KEY) @@ -19,12 +20,7 @@ def process(input, entities): output['output'] = TextTemplate('Location: ' + location_data[0]['display_name'] + '\nTime: ' + time + ' ' + time_data['abbreviation']).get_message() output['success'] = True except: - error_message = """\ - I couldn't get the time at the location you specified. - Please ask me something else, like: - - time in new york - - india time - - time at paris""" + error_message = LOCATION_ERROR.format('time') + EXAMPLE_TIME output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/weather.py b/modules/src/weather.py index 3bd31dbb..326baaf0 100644 --- a/modules/src/weather.py +++ b/modules/src/weather.py @@ -2,6 +2,7 @@ import config import os from templates.text import TextTemplate +from error_msg import LOCATION_ERROR, EXAMPLE_WEATHER MAPQUEST_CONSUMER_KEY = os.environ.get('MAPQUEST_CONSUMER_KEY', config.MAPQUEST_CONSUMER_KEY) OPEN_WEATHER_MAP_ACCESS_TOKEN = os.environ.get('OPEN_WEATHER_MAP_ACCESS_TOKEN', config.OPEN_WEATHER_MAP_ACCESS_TOKEN) @@ -19,12 +20,7 @@ def process(input, entities): output['output'] = TextTemplate('Location: ' + location_data[0]['display_name'] + '\nWeather: ' + weather_data['weather'][0]['description'] + '\nTemperature: ' + str(weather_data['main']['temp']) + ' ' + degree_sign + 'C / ' + str(temperature_in_fahrenheit) + ' ' + degree_sign + 'F\n- Info provided by OpenWeatherMap').get_message() output['success'] = True except: - error_message = """\ - I couldn't get the weather info you asked for. - Please ask me something else, like: - - tell me the weather in London - - weather Delhi - - What's the weather in Texas?""" + error_message = LOCATION_ERROR.format('weather') + EXAMPLE_WEATHER output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/wiki.py b/modules/src/wiki.py index 656a848c..2eea89ad 100644 --- a/modules/src/wiki.py +++ b/modules/src/wiki.py @@ -2,6 +2,7 @@ import wikipedia from templates.generic import * from templates.text import TextTemplate +from error_msg import QUERY_ERROR, EXAMPLE_WIKI def process(input, entities): output = {} @@ -45,12 +46,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = """\ - I couldn't find any wikipedia results matching your query. - Please ask me something else, like: - - wikipedia barack - - html wiki - - who is sachin tendulkar""" + error_message = QUERY_ERROR.format('wikipedia results') + EXAMPLE_WIKI output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output From 2d792b8a42eb5b9b3f61a9a11c8c03e984f5ea2b Mon Sep 17 00:00:00 2001 From: Zachary Williamson Date: Sat, 24 Jun 2017 12:31:08 -0500 Subject: [PATCH 3/4] Adjusted video.py in line with previous commit. --- modules/src/error_msg.py | 5 +++++ modules/src/video.py | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/src/error_msg.py b/modules/src/error_msg.py index 70ea9cc0..dcf5144c 100644 --- a/modules/src/error_msg.py +++ b/modules/src/error_msg.py @@ -39,6 +39,11 @@ - india time - time at paris""" +EXAMPLE_VIDEOS = """ + - sia videos + - videos by eminem + - video coldplay""" + EXAMPLE_WEATHER = """ - tell me the weather in London - weather Delhi diff --git a/modules/src/video.py b/modules/src/video.py index 5f2a9fec..1b2712b4 100644 --- a/modules/src/video.py +++ b/modules/src/video.py @@ -4,6 +4,7 @@ import os from templates.generic import * from templates.text import TextTemplate +from error_msg import QUERY_ERROR YOUTUBE_DATA_API_KEY = os.environ.get('YOUTUBE_DATA_API_KEY', config.YOUTUBE_DATA_API_KEY) @@ -28,12 +29,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = """\ - I couldn't find any videos matching your query. - Please ask me something else, like: - - sia videos - - videos by eminem - - video coldplay""" + error_message = QUERY_ERROR.format('videos') + EXAMPLE_VIDEOS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output From f1ba941ede457344bc201181eac9b71b053590aa Mon Sep 17 00:00:00 2001 From: Zachary Williamson Date: Sat, 8 Jul 2017 12:17:42 -0500 Subject: [PATCH 4/4] Created examples.py with valid queries for testing/messages. --- examples.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples.py diff --git a/examples.py b/examples.py new file mode 100644 index 00000000..16fbefcd --- /dev/null +++ b/examples.py @@ -0,0 +1,49 @@ +EXAMPLE_ANIME = """ + - Death Note anime, + - Dragon ball super anime status, + - What is the anime rating of One Punch Man?""" + +EXAMPLE_BOOKS = """ + - book timeline + - harry potter book plot + - little women book rating""" + +EXAMPLE_CONVERSIONS = """ + - HKD to USD + - USD to EUR rate + - how much is 100 USD to INR""" + +EXAMPLE_DEFINITIONS = """ + - define comfort + - cloud definition + - what does an accolade mean?""" + +EXAMPLE_LYRICS = """ + - paradise lyrics + - lyrics of the song hall of fame + - What are the lyrics to see you again?""" + +EXAMPLE_MOVIES = """ + - batman movie + - iron man 2 movie plot + - What is the rating of happiness movie?""" + +EXAMPLE_TIME = """ + - time in new york + - india time + - time at paris""" + +EXAMPLE_VIDEOS = """ + - sia videos + - videos by eminem + - video coldplay""" + +EXAMPLE_WEATHER = """ + - tell me the weather in London + - weather Delhi + - What's the weather in Texas?""" + +EXAMPLE_WIKI = """ + - wikipedia barack + - html wiki + - who is sachin tendulkar""" \ No newline at end of file