@@ -32,24 +32,30 @@ def run_module():
32
32
33
33
sys .exit (1 )
34
34
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 ):
36
41
"""Post complaints to Slack."""
37
42
if not params ["slack_token" ]:
38
43
print ("\b (dry-run)" )
39
44
return
40
45
41
- blocks = format_complaints (complaints )
42
-
43
46
client = WebClient (token = params ["slack_token" ])
44
47
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" ]
53
59
54
60
def format_complaints (complaints ):
55
61
"""Build a formatted Slack message for posting to the API.
0 commit comments