-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e6fcf7
commit e322d31
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
'video', | ||
'weather', | ||
'wiki', | ||
'xkcd', | ||
] | ||
|
||
# List of modules that send data personalized to the user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import requests | ||
from templates.text import TextTemplate | ||
import json | ||
import config | ||
|
||
def process(input, entities=None): | ||
output = {} | ||
try: | ||
r = requests.get('http://xkcd.com/info.0.json') | ||
data = r.json() | ||
number = data['num'] | ||
title = data['title'] | ||
link = data['img'] | ||
|
||
output['input'] = input | ||
output['output'] = TextTemplate('Number: ' + number + '\nTitle: ' + title + '\nLink: ' + link).get_message() | ||
output['success'] = True | ||
except: | ||
error_message = 'Error retrieving latest XKCD' | ||
ouput['error_message'] = TextTemplate(error_message).get_message() | ||
output['success'] = False | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import modules | ||
|
||
def test_xkcd(): | ||
assert('xkcd' == modules.process_query('Show me the latest xkcd')[0]) | ||
assert('xkcd' == modules.process_query('current xkcd')[0]) | ||
assert('xkcd' == modules.process_query('show me an xkcd')[0]) | ||
assert('xkcd' != modules.process_query('tell me a joke')[0]) |