Added CurseProfile proxy function in the client

This commit is contained in:
Frisk 2021-05-08 11:20:47 +02:00
parent 501607b60b
commit 79f2f36e23
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 15 additions and 8 deletions

View file

@ -18,7 +18,7 @@ from __future__ import annotations
import src.misc import src.misc
from typing import Union from typing import Union
from collections import OrderedDict from collections import OrderedDict
from typing import TYPE_CHECKING from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING: if TYPE_CHECKING:
from src.wiki import Wiki from src.wiki import Wiki
@ -49,6 +49,15 @@ class Client:
link_parser.feed(summary) link_parser.feed(summary)
return link_parser.new_string 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): 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. """Method to GET request data from the wiki's API with error handling including recognition of MediaWiki errors.

View file

@ -427,15 +427,13 @@ class Wiki(object):
def pull_comment(self, comment_id): def pull_comment(self, comment_id):
try: try:
comment = self.handle_mw_errors(self._safe_request( comment = self.api_request("?action=comment&do=getRaw&comment_id={comment}&format=json".format(wiki=WIKI_API_PATH,
"{wiki}?action=comment&do=getRaw&comment_id={comment}&format=json".format(wiki=WIKI_API_PATH, comment=comment_id), "text")
comment=comment_id)).json())[
"text"]
logger.debug("Got the following comment from the API: {}".format(comment)) logger.debug("Got the following comment from the API: {}".format(comment))
except MWError: except (ServerError, MediaWikiError):
pass pass
except (TypeError, AttributeError): except (BadRequest, ClientError):
logger.exception("Could not resolve the comment text.") logger.exception("Some kind of issue while creating a request (most likely client error).")
except KeyError: except KeyError:
logger.exception("CurseProfile extension API did not respond with a valid comment content.") logger.exception("CurseProfile extension API did not respond with a valid comment content.")
else: else: