From 96b9f07eba4100522df13ffb7a90b5954fddfe46 Mon Sep 17 00:00:00 2001 From: Mai Nakagawa Date: Thu, 1 Jun 2023 12:02:25 +0900 Subject: [PATCH 1/3] Misc fix --- lib/slack.py | 17 +++++++++-------- lib/utils.py | 3 ++- summarizer.py | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/slack.py b/lib/slack.py index 38f0344..fd055fb 100644 --- a/lib/slack.py +++ b/lib/slack.py @@ -11,11 +11,12 @@ class SlackClient: """ A class for managing a Slack bot client. Args: - token (str): The Slack Bot token used to authenticate with the Slack API. + slack_api_token (str): The Slack Bot token used to authenticate with the Slack API. + summary_channel (str): The Slack channel ID where the summary is posted. Example: ``` - client = SlackClient(SLACK_BOT_TOKEN) + client = SlackClient(SLACK_BOT_TOKEN, SUMMARY_CHANNEL_ID) client.postSummary(text) ``` """ @@ -59,8 +60,8 @@ def load_messages(self, channel_id: str, start_time: datetime, self._wait_api_call() result = retry(lambda: self.client.conversations_history( channel=channel_id, - oldest=start_time.timestamp(), - latest=end_time.timestamp(), + oldest=str(start_time.timestamp()), + latest=str(end_time.timestamp()), limit=1000), exception=SlackApiError) messages_info.extend(result["messages"]) @@ -77,8 +78,8 @@ def load_messages(self, channel_id: str, start_time: datetime, result = retry(lambda: self.client.conversations_history( channel=channel_id, - oldest=start_time.timestamp(), - latest=end_time.timestamp(), + oldest=str(start_time.timestamp()), + latest=str(end_time.timestamp()), limit=1000), exception=SlackApiError) else: @@ -89,8 +90,8 @@ def load_messages(self, channel_id: str, start_time: datetime, self._wait_api_call() result = retry(lambda: self.client.conversations_history( channel=channel_id, - oldest=start_time.timestamp(), - latest=end_time.timestamp(), + oldest=str(start_time.timestamp()), + latest=str(end_time.timestamp()), limit=1000, cursor=result["response_metadata"]["next_cursor"]), exception=SlackApiError) diff --git a/lib/utils.py b/lib/utils.py index 9f0e062..3e30f40 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -12,6 +12,7 @@ def retry(func, max_retries=5, sleep_time=10, exception=Exception): func (callable): The function to be wrapped. max_retries (int, optional): The maximum number of retries. Defaults to 5. sleep_time (int, optional): The sleep time in seconds between retries. Defaults to 10. + exception (Exception, optional): The expected exception class to catch and retry if raised. Defaults to Exception. Returns: result of func call. @@ -82,4 +83,4 @@ def remove_emoji(text: str) -> str: # Remove Slack custom emojis custom_pattern = r":[-_a-zA-Z0-9]+?:" text = re.sub(custom_pattern, "", text) - return text \ No newline at end of file + return text diff --git a/summarizer.py b/summarizer.py index 868b8c4..457f780 100644 --- a/summarizer.py +++ b/summarizer.py @@ -190,8 +190,8 @@ def runner(): messages = list(map(remove_emoji, messages)) result_text.append(f"----\n<#{channel['id']}>\n") - for spilitted_messages in split_messages_by_token_count(messages): - text = summarize("\n".join(spilitted_messages), LANGUAGE) + for splitted_messages in split_messages_by_token_count(messages): + text = summarize("\n".join(splitted_messages), LANGUAGE) result_text.append(text) title = (f"{start_time.strftime('%Y-%m-%d')} public channels summary\n\n") From f842d379e1f94a240de9af6292a0c9c5bdccc13e Mon Sep 17 00:00:00 2001 From: Mai Nakagawa Date: Thu, 1 Jun 2023 13:22:29 +0900 Subject: [PATCH 2/3] docstring --- lib/slack.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/slack.py b/lib/slack.py index fd055fb..fa73130 100644 --- a/lib/slack.py +++ b/lib/slack.py @@ -42,7 +42,6 @@ def load_messages(self, channel_id: str, start_time: datetime, channel_id (str): The ID of the channel to retrieve the chat history for. start_time (datetime): The start time of the time range to retrieve chat history for. end_time (datetime): The end time of the time range to retrieve chat history for. - users (list): A list of dictionaries containing information about each user in the Slack workspace. Returns: list: A list of chat messages from the specified channel, in the format "Speaker: Message". From b4191f514f5db1e065e531bee8c5c0d776e806fb Mon Sep 17 00:00:00 2001 From: Mai Nakagawa Date: Thu, 1 Jun 2023 14:17:56 +0900 Subject: [PATCH 3/3] typo --- lib/slack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack.py b/lib/slack.py index fa73130..82e85a2 100644 --- a/lib/slack.py +++ b/lib/slack.py @@ -111,7 +111,7 @@ def load_messages(self, channel_id: str, start_time: datetime, # Get speaker name speaker_name = self.get_user_name(message["user"]) or "somebody" - # Get message body fro result dict. + # Get message body from result dict. body_text = message["text"].replace("\n", "\\n") # Replace User IDs in a chat message text with user names.