Skip to content

Commit

Permalink
lns: fix view all
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed Feb 6, 2024
1 parent 12f5178 commit b38de38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Library-Notification-Service/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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!")
Expand Down
4 changes: 3 additions & 1 deletion Library-Notification-Service/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<h1>Latest books/e-books for {title}</h1>\n<ul>\n"
html_string = f"<h4>Latest books/e-books for {title}</h4>\n<ul>\n"
for doc in message:
doc_id = doc.get("id", "")
if doc_id:
Expand All @@ -109,6 +109,8 @@ def create_channel_message(message: List[dict], title: str, url: str) -> str:
doc_title = doc.get("metadata", {}).get("title", "")
html_string += f"<li><a href='{doc_url}'>{doc_title}</a></li>\n"
html_string += "</ul>"

# if len(message) > 10:
html_string += f"<p><a href='{url}'>View all</a></p>"

return html_string

0 comments on commit b38de38

Please sign in to comment.