-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add book module * Fix typo, remove unused import * Add test for book * Add attribution to Goodreads
- Loading branch information
1 parent
656727f
commit 91d7039
Showing
4 changed files
with
38 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
ACCESS_TOKEN = '<ACCESS_TOKEN>' | ||
VERIFY_TOKEN = '<VERIFY_TOKEN>' | ||
WIT_AI_ACCESS_TOKEN = 'IKJJJYYVR3X672DHFVS7U7C4L2MQSS2P' | ||
GOODREADS_ACCESS_TOKEN = '<GOODREADS_ACCESS_TOKEN>' |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__all__ = [ | ||
'book', | ||
'dictionary', | ||
'hello', | ||
'help', | ||
|
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,29 @@ | ||
import requests | ||
import config | ||
import os | ||
from xml.etree import ElementTree | ||
|
||
GOODREADS_ACCESS_TOKEN = os.environ.get('GOODREADS_ACCESS_TOKEN', config.GOODREADS_ACCESS_TOKEN) | ||
|
||
def process(input, entities=None): | ||
output = {} | ||
try: | ||
book_title = entities['book'][0]['value'] | ||
response = requests.get('https://www.goodreads.com/book/title.xml?key='+GOODREADS_ACCESS_TOKEN+'&title=' + book_title) | ||
data = ElementTree.fromstring(response.content) | ||
|
||
book_node = data.find('book') | ||
title = book_node.find('title').text | ||
description = book_node.find('description').text | ||
link = book_node.find('link').text | ||
average_rating = book_node.find('average_rating').text | ||
goodreads_attribute = "This data is powered by Goodreads" | ||
|
||
output_data = (title, description, average_rating, link, goodreads_attribute) | ||
|
||
output['input'] = input | ||
output['output'] = "Title: %s<br/>Description: %s<br/>Average Rating: %s<br/> Book link: %s<br/><br/>%s" % output_data | ||
output['success'] = True | ||
except: | ||
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_book(): | ||
assert('book' == modules.process_query('book timeline')[0]) | ||
assert('book' == modules.process_query('have you read harry potter?')[0]) | ||
assert('book' == modules.process_query('little women book rating')[0]) | ||
assert('book' != modules.process_query('harry potter movie')[0]) |