From ee4ce1fff0c45c714b22af6797558de85c52c6d7 Mon Sep 17 00:00:00 2001 From: Advith Chelikani Date: Sat, 23 Apr 2016 17:44:17 -0700 Subject: [PATCH] module for pulling random quotes programming quotes for now --- modules/src/__init__.py | 1 + modules/src/quote.py | 15 +++++++++++++++ modules/tests/test_quote.py | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 modules/src/quote.py create mode 100644 modules/tests/test_quote.py diff --git a/modules/src/__init__.py b/modules/src/__init__.py index 4813f885..2efe4b56 100644 --- a/modules/src/__init__.py +++ b/modules/src/__init__.py @@ -5,6 +5,7 @@ 'help', 'joke', 'movie', + 'quote', 'request', 'wiki' ] diff --git a/modules/src/quote.py b/modules/src/quote.py new file mode 100644 index 00000000..0c2e7999 --- /dev/null +++ b/modules/src/quote.py @@ -0,0 +1,15 @@ +import re +import requests + +def process(input, entities=None): + output = {} + try: + # Programming quotes + r = requests.get('http://quotes.stormconsultancy.co.uk/random.json') + data = r.json() + output['input'] = input + output['output'] = data['quote'] + " - " + data['author'] + output['success'] = True + except: + output['success'] = False + return output diff --git a/modules/tests/test_quote.py b/modules/tests/test_quote.py new file mode 100644 index 00000000..000de156 --- /dev/null +++ b/modules/tests/test_quote.py @@ -0,0 +1,7 @@ +import modules + +def test_quote(): + assert('quote' == modules.process_query('quote')[0]) + assert('quote' == modules.process_query('random quote')[0]) + assert('quote' == modules.process_query('give me a quote')[0]) + assert('quote' != modules.process_query('something random')[0])