From 79f2f36e2374e116688f6364d01cd22aec798253 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sat, 8 May 2021 11:20:47 +0200 Subject: [PATCH] Added CurseProfile proxy function in the client --- src/api/client.py | 11 ++++++++++- src/wiki.py | 12 +++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/api/client.py b/src/api/client.py index d290349..f9b7645 100644 --- a/src/api/client.py +++ b/src/api/client.py @@ -18,7 +18,7 @@ from __future__ import annotations import src.misc from typing import Union from collections import OrderedDict -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional if TYPE_CHECKING: from src.wiki import Wiki @@ -49,6 +49,15 @@ class Client: link_parser.feed(summary) return link_parser.new_string + def pull_curseprofile_comment(self, comment_id) -> Optional[str]: + """Pulls a CurseProfile comment for current wiki set in the settings and with comment_id passed as an argument. + + Returns: + String if comment was possible to be fetched + None if not + """ + return self.__recent_changes.pull_comment(comment_id) + def make_api_request(self, params: Union[str, OrderedDict], *json_path: str, timeout: int = 10, allow_redirects: bool = False): """Method to GET request data from the wiki's API with error handling including recognition of MediaWiki errors. diff --git a/src/wiki.py b/src/wiki.py index 185e9b6..322778a 100644 --- a/src/wiki.py +++ b/src/wiki.py @@ -427,15 +427,13 @@ class Wiki(object): def pull_comment(self, comment_id): try: - comment = self.handle_mw_errors(self._safe_request( - "{wiki}?action=comment&do=getRaw&comment_id={comment}&format=json".format(wiki=WIKI_API_PATH, - comment=comment_id)).json())[ - "text"] + comment = self.api_request("?action=comment&do=getRaw&comment_id={comment}&format=json".format(wiki=WIKI_API_PATH, + comment=comment_id), "text") logger.debug("Got the following comment from the API: {}".format(comment)) - except MWError: + except (ServerError, MediaWikiError): pass - except (TypeError, AttributeError): - logger.exception("Could not resolve the comment text.") + except (BadRequest, ClientError): + logger.exception("Some kind of issue while creating a request (most likely client error).") except KeyError: logger.exception("CurseProfile extension API did not respond with a valid comment content.") else: