Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some small bugs #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions doughnut.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def execute_channel_matches(
new_match_history: List[Dict[str, str]] = [{
'name1': match['user1']['name'],
'name2': match['user2']['name'],
'conversation_id': match["conversation_id"],
'conversation_id': match.get("conversation_id"),
'match_date': today,
'prompted': '0'
} for match in matches]
Expand Down Expand Up @@ -373,9 +373,12 @@ def pull_history_from_s3(bucket_name: str, out_dir: str = "/tmp/"):
bucket = S3_CLIENT.Bucket(bucket_name)
print(f"Pulling history from s3://{bucket_name}")
for s3_object in bucket.objects.all():
_, filename = os.path.split(s3_object.key)
print(f"Pulling history for channel {filename}")
bucket.download_file(s3_object.key, f"{out_dir}{filename}")
if not s3_object.key.endswith("/"): # Only want top level files, no folders
_, filename = os.path.split(s3_object.key)
if len(filename) > 0: # Double check we have a valid object name
dest = f"{out_dir}{filename}"
print(f"Pulling history for channel '{filename}'. Saving to '{dest}'")
bucket.download_file(s3_object.key, dest)


def push_history_to_s3(bucket_name: str, channel: str, history_dir: str = "/tmp/"):
Expand Down
16 changes: 12 additions & 4 deletions slack_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,19 @@ def post_matches(session: WebClient, matches: List[Dict], channel_id: str) -> Sl
"""
preview_message: str = ":doughnut: Matches are in! :doughnut:"

match_message: str = "The matches for this round:"
match_messages = []
msg: str = "The matches for this round:"
for match in matches:
user1_id: str = match['user1']['id']
user2_id: str = match['user2']['id']
match_message += f'\n<@{user1_id}> and <@{user2_id}>'
msg += f'\n<@{user1_id}> and <@{user2_id}>'
if len(msg) > 2500:
match_messages.append(msg)
msg = ""

# Don't forget to capture the last one!
# ...or the first one if it's less than 2500 chars
match_messages.append(msg)

blocks: List[Block] = Block.parse_all([
{
Expand Down Expand Up @@ -230,9 +238,9 @@ def post_matches(session: WebClient, matches: List[Dict], channel_id: str) -> Sl
"type": "section",
"text": {
"type": "mrkdwn",
"text": match_message
"text": message
}
},
} for message in match_messages,
{
"type": "divider"
},
Expand Down