Skip to content

Commit

Permalink
bots: Move Google search bot and fix bugs.
Browse files Browse the repository at this point in the history
Now this bot follows our latest structure for contrib_bots.

Switched the dependencies instructions, to install "google" rather than
"google-api-python-client".

Added all the search terms to the query (not only the first one).
  • Loading branch information
YagoGG authored and showell committed Mar 17, 2017
1 parent 49c2472 commit eb3304b
Showing 1 changed file with 6 additions and 20 deletions.
Expand Up @@ -3,13 +3,12 @@
import logging
import http.client
from six.moves.urllib.request import urlopen
from google import search

# Uses Google's Client Library
# pip install --upgrade google-api-python-client
# Uses the Google search engine bindings
# pip install --upgrade google
from google import search

def get_google_result(original_content):
search_keywords = original_content.strip().split(' ', 1)[1]
def get_google_result(search_keywords):
if search_keywords == 'help':
help_message = "To use this bot start message with @google \
followed by what you want to search for. If \
Expand All @@ -29,7 +28,7 @@ def get_google_result(original_content):
return 'Error: Search failed. {}.'.format(e)

if not urls:
return "No URLs returned by google."
return 'No URLs returned by google.'

url = next(urls)

Expand All @@ -53,19 +52,6 @@ def usage(self):
should preface messages with @google.
'''

def triage_message(self, message, client):
# return True if we want to (possibly) respond to this message

original_content = message['content']

# This next line of code is defensive, as we
# never want to get into an infinite loop of posting google
# search links.
if message['display_recipient'] == 'google':
return False

return original_content.startswith('@google')

def handle_message(self, message, client, state_handler):
original_content = message['content']
original_sender = message['sender_email']
Expand All @@ -90,7 +76,7 @@ def handle_message(self, message, client, state_handler):
def test():
try:
urlopen('http://216.58.192.142', timeout=1)
print("Success")
print('Success')
return True
except http.client.RemoteDisconnected as e:
print('Error: {}'.format(e))
Expand Down

0 comments on commit eb3304b

Please sign in to comment.