Skip to content

Commit

Permalink
incorporated KC recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjelstad committed Oct 20, 2023
1 parent bc93e85 commit 38eeedc
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions circuit_maintenance_parser/parsers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# pylint: disable=too-many-nested-blocks, too-many-branches

logger = logging.getLogger(__name__)
# logger.setLevel("DEBUG")


class SubjectParserAWS1(EmailSubjectParser):
Expand All @@ -27,7 +26,7 @@ def parse_subject(self, subject):
data = {"account": ""}
# Common Subject strings for matching:
subject_map = {
"\[AWS Account ?I?D?: ([0-9]+)\]": "account",
r"\[AWS Account ?I?D?: ([0-9]+)\]": "account",
}

regex_keys = re.compile("|".join(subject_map), re.IGNORECASE)
Expand All @@ -39,10 +38,11 @@ def parse_subject(self, subject):
if not line_matched:
continue
for group_match in line_matched.groups():
if group_match is not None:
for k, v in subject_map.items():
if re.search(k, line, re.IGNORECASE):
data[v] = group_match
if not group_match:
continue
for key, value in subject_map.items():
if re.search(key, line, re.IGNORECASE):
data[value] = group_match
return [data]


Expand Down Expand Up @@ -107,19 +107,20 @@ def parse_text(self, text):
# for lines that do match our regex strings.
# grab the data and map the values to keys.
for group_match in line_matched.groups():
if group_match is not None:
for k, v in text_map.items():
if re.search(k, line_matched.string, re.IGNORECASE):
# Due to having a single line on some emails
# This causes multiple match groups
# However this needs to be split across keys.
# This could probably be cleaned up.
if v == "start_and_end" and data["start"] == "":
data["start"] = group_match
elif v == "start_and_end" and data["end"] == "":
data["end"] = group_match
else:
data[v] = group_match
if not group_match:
continue
for key, value in text_map.items():
if re.search(key, line_matched.string, re.IGNORECASE):
# Due to having a single line on some emails
# This causes multiple match groups
# However this needs to be split across keys.
# This could probably be cleaned up.
if value == "start_and_end" and data["start"] == "":
data["start"] = group_match
elif value == "start_and_end" and data["end"] == "":
data["end"] = group_match
else:
data[value] = group_match

# Let's determine impact and status
if "may become unavailable" in line.lower():
Expand Down

0 comments on commit 38eeedc

Please sign in to comment.