Skip to content

Commit e75ff69

Browse files
authored
Merge pull request #466 from cmu-delphi/sir-cal/fix-slack-errors
Fix errors in Sir-Complains-a-lot
2 parents c303bc1 + 23bcf64 commit e75ff69

File tree

1 file changed

+17
-11
lines changed
  • sir_complainsalot/delphi_sir_complainsalot

1 file changed

+17
-11
lines changed

sir_complainsalot/delphi_sir_complainsalot/run.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,30 @@ def run_module():
3232

3333
sys.exit(1)
3434

35-
def report_complaints(complaints, params):
35+
def split_complaints(complaints, n=49):
36+
"""Yield successive n-sized chunks from complaints list."""
37+
for i in range(0, len(complaints), n):
38+
yield complaints[i:i + n]
39+
40+
def report_complaints(all_complaints, params):
3641
"""Post complaints to Slack."""
3742
if not params["slack_token"]:
3843
print("\b (dry-run)")
3944
return
4045

41-
blocks = format_complaints(complaints)
42-
4346
client = WebClient(token=params["slack_token"])
4447

45-
try:
46-
client.chat_postMessage(
47-
channel=params["channel"],
48-
blocks=blocks
49-
)
50-
except SlackApiError as e:
51-
# You will get a SlackApiError if "ok" is False
52-
assert e.response["error"]
48+
for complaints in split_complaints(all_complaints):
49+
blocks = format_complaints(complaints)
50+
print(f"blocks: {len(blocks)}")
51+
try:
52+
client.chat_postMessage(
53+
channel=params["channel"],
54+
blocks=blocks
55+
)
56+
except SlackApiError as e:
57+
# You will get a SlackApiError if "ok" is False
58+
assert False, e.response["error"]
5359

5460
def format_complaints(complaints):
5561
"""Build a formatted Slack message for posting to the API.

0 commit comments

Comments
 (0)