From b0bd660fb0ea62bffae1dc66ae4495c206be54a8 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 13 Aug 2023 12:44:19 +0200 Subject: [PATCH] fixes --- requirements.txt | 2 +- src/discussions.py | 3 +-- src/wiki.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index e51df3e..9d89520 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ nest-asyncio >= 1.4.0 irc >= 19.0.1 beautifulsoup4>=4.9.3 asyncpg>=0.22.0 -aioredis >= 1.3.1 \ No newline at end of file +requests>=2.31.0 \ No newline at end of file diff --git a/src/discussions.py b/src/discussions.py index 3e3ea02..d49bb61 100644 --- a/src/discussions.py +++ b/src/discussions.py @@ -98,8 +98,7 @@ class Discussions: params = {"controller": "FeedsAndPosts", "method": "getArticleNamesAndUsernames", "stablePageIds": ",".join(comment_events), "format": "json"} comment_pages_request = await wiki.fetch_discussions(params) - comment_pages = await comment_pages_request.json() - comment_pages = comment_pages["articleNames"] + comment_pages = comment_pages_request[1]["articleNames"] except aiohttp.ClientResponseError: # Fandom can be funny sometimes... See #30 comment_pages = None except: diff --git a/src/wiki.py b/src/wiki.py index dfc4428..c1c4a95 100644 --- a/src/wiki.py +++ b/src/wiki.py @@ -393,6 +393,22 @@ class Wiki: raise WikiServerError(e) return feeds_response, await feeds_response.json(encoding="UTF-8") + def pull_comment(self, comment_id): + try: + comment = self.sync_api_request("?action=comment&do=getRaw&comment_id={comment}&format=json".format(comment=comment_id), "text") + logger.debug("Got the following comment from the API: {}".format(comment)) + except (ServerError, MediaWikiError): + pass + 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: + if len(comment) > 1000: + comment = comment[0:1000] + "…" + return comment + return "" + def process_cachable(response: dict, wiki_object: Wiki) -> None: """This function processes cachable objects – such as MediaWiki system messages and wiki tag display names to be used