From 6a6e789ec9e3c6dd365922ac630a405b830e8c1a Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 25 Nov 2019 18:17:30 +0000 Subject: add `cookies` and `.json()` to utils.http.Response objects --- modules/imgur.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'modules/imgur.py') diff --git a/modules/imgur.py b/modules/imgur.py index 30208c36..35bb6329 100644 --- a/modules/imgur.py +++ b/modules/imgur.py @@ -48,11 +48,10 @@ class Module(ModuleManager.BaseModule): def _parse_gallery(self, hash): api_key = self.bot.config["imgur-api-key"] result = utils.http.request(URL_GALLERY % hash, - headers={"Authorization": "Client-ID %s" % api_key}, - json=True) + headers={"Authorization": "Client-ID %s" % api_key}).json() - if result and result.data["success"]: - data = result.data["data"] + if result and result["success"]: + data = result["data"] text = "" nsfw = utils.irc.bold(NSFW_TEXT) + " " if data["nsfw"] else "" @@ -75,11 +74,10 @@ class Module(ModuleManager.BaseModule): def _parse_image(self, hash): api_key = self.bot.config["imgur-api-key"] result = utils.http.request(URL_IMAGE % hash, - headers={"Authorization": "Client-ID %s" % api_key}, - json=True) + headers={"Authorization": "Client-ID %s" % api_key}).json() - if result and result.data["success"]: - data = result.data["data"] + if result and result["success"]: + data = result["data"] text = "" nsfw = utils.irc.bold(NSFW_TEXT) + " " if data["nsfw"] else "" @@ -102,11 +100,10 @@ class Module(ModuleManager.BaseModule): def _image_info(self, hash): api_key = self.bot.config["imgur-api-key"] result = utils.http.request(URL_IMAGE % hash, - headers={"Authorization": "Client-ID %s" % api_key}, - json=True) + headers={"Authorization": "Client-ID %s" % api_key}).json() - if result and result.data["success"]: - data = result.data["data"] + if result and result["success"]: + data = result["data"] text = self._prefix(data) text += "(%s %dx%d, %d views)" % (data["type"], data["width"], @@ -120,11 +117,10 @@ class Module(ModuleManager.BaseModule): def _gallery_info(self, hash): api_key = self.bot.config["imgur-api-key"] result = utils.http.request(URL_GALLERY % hash, - headers={"Authorization": "Client-ID %s" % api_key}, - json=True) + headers={"Authorization": "Client-ID %s" % api_key}).json() - if result and result.data["success"]: - data = result.data["data"] + if result and result["success"]: + data = result["data"] text = self._prefix(data) text += "(%d views, %d▲▼%d)" % (data["views"], data["ups"], data["downs"]) -- cgit v1.3.1-10-gc9f91