Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Update website search results for new Wagtail API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jun 17, 2024
1 parent c52088f commit db5a8f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/articles/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class Article(APISearchResult):
url: str = ""
type: str = ""
first_published: str = ""
type_label: str = ""
# first_published: str = ""
image: dict | None = None

def __str__(self):
Expand Down
3 changes: 2 additions & 1 deletion app/sources/rosetta/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
)
from app.schemas import Filter
from config import Config
# from pydash import objects

from .lib import RosettaResponseParser, RosettaSourceParser

# from pydash import objects


class RosettaRecords(GetAPI):
api_base_url = Config().ROSETTA_API_URL
Expand Down
17 changes: 4 additions & 13 deletions app/sources/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,17 @@ def get_result(self, page: int | None = 1) -> dict:
offset = (page - 1) * self.results_per_page
self.add_parameter("offset", offset)
self.add_parameter("limit", self.results_per_page)
# self.add_parameter("fields", "search_description,teaser_image_jpg") # TODO: Not all pages have a teaser image
self.add_parameter("fields", "search_description")
url = self.build_url()
raw_results = self.execute(url)
response = ArticleSearchResults()
for a in raw_results["items"]:
article = Article()
article.title = a["title"]
article.url = a["meta"]["html_url"]
article.type = a["meta"]["type"]
article.url = a["full_url"]
article.type_label = a["type_label"]
article.id = a["id"]
article.first_published = a["meta"]["first_published_at"]
article.description = a["meta"]["search_description"]
# article.image = a["teaser_image_jpg"]
# TODO: Temp until all pages have a teaser_image
page_details_api = WebsiteArticles()
page_details_url = f"{self.api_base_url}{self.api_path}{article.id}"
page_details = page_details_api.execute(page_details_url)
article.description = page_details["meta"]["search_description"]
article.image = page_details["teaser_image"]["image_jpeg"]
article.description = a["teaser_text"]
article.image = a["teaser_image"]
response.results.append(article)
response.count = raw_results["meta"]["total_count"]
response.results_per_page = self.results_per_page
Expand Down

0 comments on commit db5a8f3

Please sign in to comment.