Skip to content

Commit 8d00ead

Browse files
Reflow and rename stuff
1 parent 9a61c03 commit 8d00ead

File tree

1 file changed

+37
-24
lines changed
  • sir_complainsalot/delphi_sir_complainsalot

1 file changed

+37
-24
lines changed

sir_complainsalot/delphi_sir_complainsalot/run.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717

1818
from .check_source import check_source
1919

20+
2021
def run_module():
2122

2223
params = read_params()
2324
meta = covidcast.metadata()
2425

2526
complaints = []
2627
for data_source in params["sources"].keys():
27-
complaints.extend(check_source(data_source, meta, params["sources"], params.get("grace", 0)))
28+
complaints.extend(check_source(data_source, meta,
29+
params["sources"], params.get("grace", 0)))
2830

2931
if len(complaints) > 0:
3032
for complaint in complaints:
@@ -34,11 +36,13 @@ def run_module():
3436

3537
sys.exit(1)
3638

39+
3740
def split_complaints(complaints, n=49):
3841
"""Yield successive n-sized chunks from complaints list."""
3942
for i in range(0, len(complaints), n):
4043
yield complaints[i:i + n]
4144

45+
4246
def report_complaints(all_complaints, params):
4347
"""Post complaints to Slack."""
4448
if not params["slack_token"]:
@@ -59,39 +63,45 @@ def report_complaints(all_complaints, params):
5963
# You will get a SlackApiError if "ok" is False
6064
assert False, e.response["error"]
6165

62-
6366
def get_maintainers_block(complaints):
6467
maintainers = set()
6568
for c in complaints:
6669
maintainers.update(c.maintainers)
67-
70+
6871
maintainers_block = {
69-
"type": "section",
70-
"text": {
71-
"type": "mrkdwn",
72-
"text": "Hi, this is Sir Complains-a-Lot. I need to speak to " +
73-
(", ".join("<@{0}>".format(m) for m in maintainers)) + "."
74-
}
75-
}
72+
"type": "section",
73+
"text": {
74+
"type": "mrkdwn",
75+
"text": "Hi, this is Sir Complains-a-Lot. I need to speak to " +
76+
(", ".join("<@{0}>".format(m)
77+
for m in maintainers)) + "."
78+
}
79+
}
7680

7781
return maintainers_block
7882

7983

8084
def format_complaints_aggregated_by_source(complaints):
81-
"""Build formatted Slack message for posting to the API, aggregating the
85+
"""Build formatted Slack message for posting to the API, aggregating
8286
complaints by source to reduce the number of blocks."""
8387

8488
blocks = [get_maintainers_block(complaints)]
8589

86-
def aggregated_message_for_source(x): return "{complaint} - (last update: {last_updated})".format(
87-
complaint=x.message, last_updated=x.last_updated.strftime("%Y-%m-%d"))
90+
def message_for_source(complaint):
91+
return "{main_text} - (last update: {last_updated})".format(
92+
main_text=complaint.message,
93+
last_updated=complaint.last_updated.strftime("%Y-%m-%d"))
8894

89-
for source, v in groupby(complaints, key=lambda x: x.data_source):
90-
for message, complaint_list in groupby(v, key=aggregated_message_for_source):
95+
for source, complaints_by_source in groupby(
96+
complaints, key=lambda x: x.data_source):
97+
for message, complaint_list in groupby(
98+
complaints_by_source, key=message_for_source):
9199
signal_and_geo_types = ""
92100
for complaint in complaint_list:
93101
signal_and_geo_types += "`{signal}: [{geo_types}]`\n".format(
94-
signal=complaint.signal, geo_types=", ".join(complaint.geo_types))
102+
signal=complaint.signal,
103+
geo_types=", ".join(complaint.geo_types))
104+
95105
blocks.extend([
96106
{
97107
"type": "divider"
@@ -100,7 +110,11 @@ def aggregated_message_for_source(x): return "{complaint} - (last update: {last_
100110
"type": "section",
101111
"text": {
102112
"type": "mrkdwn",
103-
"text": "*{source_name}* {message_for_group}:\n{signals}".format(source_name=source.upper(), message_for_group=message, signals=signal_and_geo_types)
113+
"text": "*{source_name}* {message}:\n{signals}"
114+
.format(
115+
source_name=source.upper(),
116+
message=message,
117+
signals=signal_and_geo_types)
104118
}
105119
}
106120
])
@@ -121,13 +135,12 @@ def format_complaints(complaints):
121135
for complaint in complaints:
122136
blocks.append(
123137
{
124-
"type": "section",
125-
"text": {
126-
"type": "mrkdwn",
127-
"text": complaint.to_md()
128-
}
129-
}
138+
"type": "section",
139+
"text": {
140+
"type": "mrkdwn",
141+
"text": complaint.to_md()
142+
}
143+
}
130144
)
131145

132-
133146
return blocks

0 commit comments

Comments
 (0)