Small improvements/explanations

This commit is contained in:
Frisk 2022-06-13 22:18:46 +02:00
parent 0513ec2422
commit 1e0e62f775
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 6 additions and 3 deletions

View file

@ -20,7 +20,8 @@ if TYPE_CHECKING:
class Context: class Context:
"""Context object containing client and some metadata regarding specific formatter call""" """Context object containing client and some metadata regarding specific formatter call,
they are mainly used as a bridge between part that fetches the changes and API's formatters"""
def __init__(self, message_type: str, webhook_url: str, client: Client): def __init__(self, message_type: str, webhook_url: str, client: Client):
self.client = client self.client = client
self.webhook_url = webhook_url self.webhook_url = webhook_url
@ -38,3 +39,6 @@ class Context:
def set_comment_page(self, page): def set_comment_page(self, page):
self.comment_page = page self.comment_page = page
def __str__(self):
return f"<Context message_type={self.message_type} event={self.event} webhook_url={self.webhook_url}"

View file

@ -73,7 +73,6 @@ def fetch_discussions():
return None return None
else: else:
if request_json: if request_json:
comment_pages: dict = {}
comment_events: list = [post["forumId"] for post in request_json if post["_embedded"]["thread"][0]["containerType"] == "ARTICLE_COMMENT" and int(post["id"]) > storage["discussion_id"]] comment_events: list = [post["forumId"] for post in request_json if post["_embedded"]["thread"][0]["containerType"] == "ARTICLE_COMMENT" and int(post["id"]) > storage["discussion_id"]]
if comment_events: if comment_events:
comment_pages = safe_request( comment_pages = safe_request(
@ -139,7 +138,7 @@ def parse_discussion_post(post, comment_pages):
send_to_discord(discord_message, metadata) send_to_discord(discord_message, metadata)
def safe_request(url): def safe_request(url) -> Optional[requests.Response]:
"""Function to assure safety of request, and do not crash the script on exceptions,""" """Function to assure safety of request, and do not crash the script on exceptions,"""
try: try:
request = session.get(url, timeout=10, allow_redirects=False, headers={"Accept": "application/hal+json"}) request = session.get(url, timeout=10, allow_redirects=False, headers={"Accept": "application/hal+json"})