diff --git a/chatterbot/adapters/io/io.py b/chatterbot/adapters/io/io.py index 3d812ea56..20feb8eb1 100644 --- a/chatterbot/adapters/io/io.py +++ b/chatterbot/adapters/io/io.py @@ -3,6 +3,15 @@ class IOAdapter(object): + def __init__(self, **kwargs): + pass + + def process_input(self): + """ + Returns data retrieved from the input source. + """ + raise AdapterNotImplementedError() + def process_response(self, input_value): """ Takes an input value. diff --git a/chatterbot/chatterbot.py b/chatterbot/chatterbot.py index 36cfa4142..c91f77bde 100644 --- a/chatterbot/chatterbot.py +++ b/chatterbot/chatterbot.py @@ -26,7 +26,7 @@ def __init__(self, name, **kwargs): self.logic = LogicAdapter() IOAdapter = import_module(io_adapter) - self.io = IOAdapter() + self.io = IOAdapter(**kwargs) self.recent_statements = [] diff --git a/examples/terminal_example.py b/examples/terminal_example.py index a0fb3e40e..6f6c97693 100644 --- a/examples/terminal_example.py +++ b/examples/terminal_example.py @@ -37,3 +37,4 @@ except (KeyboardInterrupt, EOFError, SystemExit): break + diff --git a/examples/twitter_example.py b/examples/twitter_example.py index 8a38ef34c..cf6e31233 100644 --- a/examples/twitter_example.py +++ b/examples/twitter_example.py @@ -1,32 +1,31 @@ -''' -Respond to mentions on twitter. -The bot will follow the user who mentioned it and -favorite the post in which the mention was made. -''' +from chatterbot import ChatBot + chatbot = ChatBot("ChatterBot", storage_adapter="chatterbot.adapters.storage.JsonDatabaseAdapter", logic_adapter="chatterbot.adapters.logic.ClosestMatchAdapter", io_adapter="chatterbot.adapters.io.TwitterAdapter", - database="../database.db") + database="../database.db", + consumer_key="xxx", + consumer_secret="xxx" +) + +''' +Respond to mentions on twitter. +The bot will follow the user who mentioned it and +favorite the post in which the mention was made. +''' -for mention in chatbot.get_mentions(): +user_input = "Type something to begin..." - ''' - Check to see if the post has been favorited - We will use this as a check for whether or not to respond to it. - Only respond to unfavorited mentions. - ''' +print(user_input) - if not mention["favorited"]: - screen_name = mention["user"]["screen_name"] - text = mention["text"] - response = chatbot.get_response(text) +while True: + try: + user_input = chatbot.get_input() - print(text) - print(response) + bot_input = chatbot.get_response(user_input) - chatbot.follow(screen_name) - chatbot.favorite(mention["id"]) - chatbot.reply(mention["id"], response) + except (KeyboardInterrupt, EOFError, SystemExit): + break diff --git a/tests/io_adapter_tests/test_twitter.py b/tests/io_adapter_tests/test_twitter.py index a4d5b874e..f566555a3 100644 --- a/tests/io_adapter_tests/test_twitter.py +++ b/tests/io_adapter_tests/test_twitter.py @@ -2,16 +2,11 @@ from chatterbot.adapters.io import TwitterAdapter -class TwitterTests(TestCase): +class TwitterAdapterTests(TestCase): - def test_consumer_stored(self): - TWITTER = { - "CONSUMER_KEY": "blahblahblah", - "CONSUMER_SECRET": "nullvoidnullvoidnullvoid" - } - - chatbot = TwitterAdapter(twitter=TWITTER) - - self.assertEqual(TWITTER["CONSUMER_KEY"], chatbot.consumer_key) - self.assertEqual(TWITTER["CONSUMER_SECRET"], chatbot.consumer_secret) + def setUp(self): + adapter = TwitterAdapter( + consumer_key="blahblahblah", + consumer_secret="nullvoidnullvoidnullvoid" + )