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

Include parameter for dynamic no result text in notification #98

Merged
merged 8 commits into from
Jun 26, 2024
Merged
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
6 changes: 2 additions & 4 deletions dag_confs/examples_and_tests/header_and_footer_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ dag:
terms:
- tecnologia
- informação
department:
- Ministério da Gestão e da Inovação em Serviços Públicos
- Ministério da Defesa
report:
emails:
- [email protected]
subject: "Teste do Ro-dou"
header_text: <p><strong>Greetings<strong></p>
footer_text: <p>Best Regards</p>
footer_text: <p>Best Regards</p>
no_results_found_text: No results found
4 changes: 4 additions & 0 deletions schemas/ro-dou.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@
"footer_text": {
"type": "string",
"description": "description"
},
"no_results_found_text": {
"type": "string",
"description": "description"
}
},
"additionalProperties": false
Expand Down
3 changes: 2 additions & 1 deletion src/notification/discord_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, specs) -> None:
self.hide_filters = specs.hide_filters
self.header_text = specs.header_text
self.footer_text = specs.footer_text
self.no_results_found_text = specs.no_results_found_text

def send(self, search_report: list, report_date: str = None):
"""Parse the content, and send message to Discord"""
Expand All @@ -34,7 +35,7 @@ def send(self, search_report: list, report_date: str = None):
self.send_embeds(items)
else:
self.send_text(
"**Nenhum dos termos pesquisados foi encontrado nesta consulta**"
f"**{self.no_results_found_text}**"
)

if self.footer_text:
Expand Down
4 changes: 2 additions & 2 deletions src/notification/email_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def send(self, search_report: list, report_date: str):
if items:
skip_notification = False
else:
content = "Nenhum dos termos pesquisados foi encontrado."
content = self.specs.no_results_found_text

if skip_notification:
if self.specs.skip_null:
Expand Down Expand Up @@ -92,7 +92,7 @@ def generate_email_content(self) -> str:

if not results:
blocks.append(
"<p>Nenhum dos termos pesquisados foi encontrado nesta consulta.</p>"
f"<p>{self.specs.no_results_found_text}.</p>"
)
else:
if not self.specs.hide_filters:
Expand Down
3 changes: 2 additions & 1 deletion src/notification/slack_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, specs) -> None:
self.hide_filters = specs.hide_filters
self.header_text = specs.header_text
self.footer_text = specs.footer_text
self.no_results_found_text = specs.no_results_found_text

def send(self, search_report: list, report_date: str = None):
"""Parse the content, and send message to Slack"""
Expand All @@ -37,7 +38,7 @@ def send(self, search_report: list, report_date: str = None):
self._add_block(item)
else:
self._add_text(
"Nenhum dos termos pesquisados foi encontrado nesta consulta."
self.no_results_found_text
)

if self.footer_text:
Expand Down
8 changes: 7 additions & 1 deletion src/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DAGConfig:
hide_filters: bool
header_text: str
footer_text: str
no_results_found_text: str


class FileParser(ABC):
Expand Down Expand Up @@ -158,6 +159,10 @@ def _parse_yaml(self) -> DAGConfig:
hide_filters = report.get("hide_filters", False)
header_text = report.get("header_text", None)
footer_text = report.get("footer_text", None)
no_results_found_text = report.get(
"no_results_found_text",
"Nenhum dos termos pesquisados foi encontrado nesta consulta",
)

return DAGConfig(
dag_id=dag_id,
Expand All @@ -175,7 +180,8 @@ def _parse_yaml(self) -> DAGConfig:
owner=owner,
hide_filters=hide_filters,
header_text=header_text,
footer_text=footer_text
footer_text=footer_text,
no_results_found_text=no_results_found_text,
)

def _get_terms_params(self, search) -> Tuple[List[str], str, str]:
Expand Down
Loading
Loading