Skip to content

Commit

Permalink
Merge pull request masuidrive#8 from mai-nakagawa/patch
Browse files Browse the repository at this point in the history
Misc fix
  • Loading branch information
masuidrive authored Jul 5, 2023
2 parents c45c7c3 + b4191f5 commit cb1bf95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
20 changes: 10 additions & 10 deletions lib/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
"""
Expand All @@ -41,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".
Expand All @@ -59,8 +59,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"])
Expand All @@ -77,8 +77,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:
Expand All @@ -89,8 +89,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)
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
return text
4 changes: 2 additions & 2 deletions summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cb1bf95

Please sign in to comment.