diff options
| author | 2019-11-26 13:41:40 +0000 | |
|---|---|---|
| committer | 2019-11-26 13:42:01 +0000 | |
| commit | 2d21dfa22931bdb887ccccba4a33e6fa4755e94b (patch) | |
| tree | 6ef5e304e3e9a69f9afd66ac0bee4d98ec115399 /modules/google.py | |
| parent | remove all `eagle` stuff from nr.py (diff) | |
| signature | ||
utils.http.Response.data should always be `bytes` - add .decode and .soup
Diffstat (limited to 'modules/google.py')
| -rw-r--r-- | modules/google.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/modules/google.py b/modules/google.py index 47700eb9..6cddb8a3 100644 --- a/modules/google.py +++ b/modules/google.py @@ -27,13 +27,13 @@ class Module(ModuleManager.BaseModule): safe = "active" if safe_setting else "off" page = utils.http.request(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", "safe": safe}, json=True) + "q": phrase, "prettyPrint": "true", "num": 1, "gl": "gb", + "key": self.bot.config["google-api-key"], + "cx": self.bot.config["google-search-id"], + "safe": safe}).json() if page: - if "items" in page.data and len(page.data["items"]): - item = page.data["items"][0] + if "items" in page and len(page["items"]): + item = page["items"][0] link = item["link"] title = utils.parse.line_normalise(item["title"]) event["stdout"].write( @@ -54,10 +54,11 @@ class Module(ModuleManager.BaseModule): phrase = event["args"] or event["target"].buffer.get() if phrase: page = utils.http.request(URL_GOOGLESUGGEST, get_params={ - "output": "json", "client": "hp", "gl": "gb", "q": phrase}) + "output": "json", "client": "hp", "gl": "gb", "q": phrase} + ).json() if page: # google gives us jsonp, so we need to unwrap it. - page = page.data.split("(", 1)[1][:-1] + page = page.split("(", 1)[1][:-1] page = json.loads(page) suggestions = page[1] suggestions = [utils.http.strip_html(s[0]) for s in suggestions] |
