mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Added CurseProfile proxy function in the client
This commit is contained in:
parent
501607b60b
commit
79f2f36e23
|
@ -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.
|
||||
|
||||
|
|
12
src/wiki.py
12
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:
|
||||
|
|
Loading…
Reference in a new issue