From b38de38e108a08698ab56058d30954395312da87 Mon Sep 17 00:00:00 2001 From: Harris Tzovanakis Date: Tue, 6 Feb 2024 13:18:13 +0100 Subject: [PATCH] lns: fix view all --- Library-Notification-Service/src/api.py | 6 ++++++ .../src/providers/library_newsletter.py | 7 +++++-- Library-Notification-Service/src/utils.py | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Library-Notification-Service/src/api.py b/Library-Notification-Service/src/api.py index 4ea5199..422022d 100644 --- a/Library-Notification-Service/src/api.py +++ b/Library-Notification-Service/src/api.py @@ -11,6 +11,7 @@ LIBRARY_CATALOGUE_BACKOFFICE_EITEMS_API, LIBRARY_CATALOGUE_BACKOFFICE_ITEMS_API, LIBRARY_CATALOGUE_SITE_API, + LIBRARY_CATALOGUE_SITE_URL, NOTIFICATIONS_API_SECRET, NOTIFICATIONS_API_URL, NOTIFICATIONS_CHANNEL_ID, @@ -62,6 +63,11 @@ def get_api_url(query: str) -> str: return f"{LIBRARY_CATALOGUE_SITE_API}{query_encoded}" +def get_catalogue_site_url(query: str) -> str: + query_encoded = urllib.parse.quote(query) + return f"{LIBRARY_CATALOGUE_SITE_URL}{query_encoded}" + + def get_results_from_pids(pids: List[str], subjects: List[str]) -> List[dict]: published = get_last_five_years_range() results = [] diff --git a/Library-Notification-Service/src/providers/library_newsletter.py b/Library-Notification-Service/src/providers/library_newsletter.py index e9590ed..9ec09ef 100644 --- a/Library-Notification-Service/src/providers/library_newsletter.py +++ b/Library-Notification-Service/src/providers/library_newsletter.py @@ -5,8 +5,8 @@ import click from ..api import ( - get_api_url, get_backoffice_latest_pids, + get_catalogue_site_url, get_results_from_pids, send_channel_request, ) @@ -54,9 +54,12 @@ def cli(subjects: Tuple[str, ...], title: str, target: str) -> None: click.echo("No results visible in the catalogue!") return - url = get_api_url(query) + url = get_catalogue_site_url(query) message = create_channel_message(results, title, url) + click.echo( + f"Subject: {subjects} - Title: {title} - Results: {len(results)} results." + ) notification_status = send_channel_request(message, target) if notification_status == 200: click.echo("Notification sent successfully!") diff --git a/Library-Notification-Service/src/utils.py b/Library-Notification-Service/src/utils.py index f803a34..03a7445 100644 --- a/Library-Notification-Service/src/utils.py +++ b/Library-Notification-Service/src/utils.py @@ -100,7 +100,7 @@ def get_pids_from_docs(docs: List[dict]) -> List[str]: def create_channel_message(message: List[dict], title: str, url: str) -> str: - html_string = f"

Latest books/e-books for {title}

\n