aboutsummaryrefslogtreecommitdiff
path: root/modules/google.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-10-03 13:22:37 +0100
committerGravatar jesopo2018-10-03 13:22:37 +0100
commit69d58eede2e9bf83aa1ed1d8fcf956efde494726 (patch)
tree11aa30f2a357f3be23ad97315dae3df051455cbe /modules/google.py
parentAdd a way to not add a user automatically in IRCServer.get_user (diff)
signature
Move src/Utils.py in to src/utils/, splitting functionality out in to modules of
related functionality
Diffstat (limited to 'modules/google.py')
-rw-r--r--modules/google.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/modules/google.py b/modules/google.py
index e30e6cda..33dee523 100644
--- a/modules/google.py
+++ b/modules/google.py
@@ -2,13 +2,13 @@
#--require-config google-search-id
import json
-from src import ModuleManager, Utils
+from src import ModuleManager, utils
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
URL_GOOGLESUGGEST = "http://google.com/complete/search"
class Module(ModuleManager.BaseModule):
- @Utils.hook("received.command.google|g")
+ @utils.hook("received.command.google|g")
def google(self, event):
"""
:help: Get first Google result for a given search term
@@ -16,15 +16,15 @@ class Module(ModuleManager.BaseModule):
"""
phrase = event["args"] or event["target"].buffer.get()
if phrase:
- page = Utils.get_url(URL_GOOGLESEARCH, get_params={
+ page = utils.http.get_url(URL_GOOGLESEARCH, get_params={
"q": phrase, "key": self.bot.config[
"google-api-key"], "cx": self.bot.config[
"google-search-id"], "prettyPrint": "true",
"num": 1, "gl": "gb"}, json=True)
if page:
if "items" in page and len(page["items"]):
- event["stdout"].write("(" + Utils.bold(phrase) + ") " \
- + page["items"][0]["link"])
+ event["stdout"].write(
+ "(%s) %s" % (phrase, page["items"][0]["link"]))
else:
event["stderr"].write("No results found")
else:
@@ -32,21 +32,21 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No phrase provided")
- @Utils.hook("received.command.suggest", usage="[phrase]")
+ @utils.hook("received.command.suggest", usage="[phrase]")
def suggest(self, event):
"""
Get suggested phrases from Google
"""
phrase = event["args"] or event["target"].buffer.get()
if phrase:
- page = Utils.get_url(URL_GOOGLESUGGEST, get_params={
+ page = utils.html.get_url(URL_GOOGLESUGGEST, get_params={
"output": "json", "client": "hp", "q": phrase})
if page:
# google gives us jsonp, so we need to unwrap it.
page = page.split("(", 1)[1][:-1]
page = json.loads(page)
suggestions = page[1]
- suggestions = [Utils.strip_html(s[0]) for s in suggestions]
+ suggestions = [utils.html.strip_html(s[0]) for s in suggestions]
if suggestions:
event["stdout"].write("%s: %s" % (phrase,