Skip to content

Commit

Permalink
made summary field optional
Browse files Browse the repository at this point in the history
  • Loading branch information
c3kay committed Dec 7, 2024
1 parent 330e35b commit 4846cbb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/hoyolabrssfeeds/hoyolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,13 @@ async def get_feed_item(
"title": post["post"]["subject"],
"author": post["user"]["nickname"],
"content": post["post"]["content"],
"summary": post["post"]["desc"],
"category": post["post"]["official_type"],
"published": post["post"]["created_at"],
}

if "desc" in post["post"] and len(post["post"]["desc"]) > 0:
item["summary"] = post["post"]["desc"]

if post["last_modify_time"] > 0:
item["updated"] = post["last_modify_time"]

Expand Down
4 changes: 3 additions & 1 deletion src/hoyolabrssfeeds/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ async def get_feed_items(self) -> List[FeedItem]:
"title": item["title"],
"author": item["authors"][0]["name"],
"content": item["content_html"],
"summary": item["summary"],
"category": category,
"published": item["date_published"],
}

if "summary" in item:
item_dict["summary"] = item["summary"]

if "date_modified" in item:
item_dict["updated"] = item["date_modified"]

Expand Down
2 changes: 1 addition & 1 deletion src/hoyolabrssfeeds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ class FeedItem(MyBaseModel):
title: str
author: str
content: str
summary: str
category: FeedItemCategory
published: datetime
updated: Optional[datetime] = None
image: Optional[HttpUrl] = None
summary: Optional[str] = None


class FeedItemMeta(MyBaseModel):
Expand Down
7 changes: 5 additions & 2 deletions src/hoyolabrssfeeds/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ def create_json_feed_item(item: FeedItem) -> Dict[str, Any]:
"authors": [{"name": item.author}],
"tags": [item.category.name.title()],
"content_html": item.content,
"summary": item.summary,
"date_published": item.published.astimezone().isoformat(),
}

if item.summary is not None:
json_item["summary"] = item.summary

if item.updated is not None:
json_item["date_modified"] = item.updated.astimezone().isoformat()

Expand Down Expand Up @@ -212,7 +214,8 @@ def create_atom_feed_entries(
item.content
)

ElementTree.SubElement(entry, "summary").text = item.summary
if item.summary is not None:
ElementTree.SubElement(entry, "summary").text = item.summary

entries.append(entry)

Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,6 @@ def validate_hoyolab_post(post: Dict[str, Any], is_full_post: bool) -> None:
assert type(post["post"]["content"]) is str
assert len(post["post"]["content"]) > 0

assert type(post["post"]["desc"]) is str
assert len(post["post"]["desc"]) > 0

assert type(post["post"]["structured_content"]) is str
assert len(post["post"]["structured_content"]) > 0

Expand All @@ -329,3 +326,6 @@ def validate_hoyolab_post(post: Dict[str, Any], is_full_post: bool) -> None:

assert type(post["cover_list"]) is list
assert len(post["cover_list"]) >= 0

assert type(post["post"]["desc"]) is str
assert len(post["post"]["desc"]) >= 0

0 comments on commit 4846cbb

Please sign in to comment.