Skip to content

Commit

Permalink
Fixed Item parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
NateShoffner committed Mar 5, 2024
1 parent 29c7845 commit 5a5586c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/tenji/model/item/item.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from pydantic import BaseModel

from tenji.model.category import ItemCategory
Expand All @@ -15,8 +16,8 @@ class Company(BaseModel):

class Item(BaseModel):
id: int
name: str
thumbnail: str
name: Optional[str]
thumbnail: Optional[str]
category: ItemCategory
characters: list[Character] = []
companies: list[Company] = []
8 changes: 4 additions & 4 deletions src/tenji/parser/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def try_get_item_fields(self, labels: list[str]) -> list[ItemField]:

return fields

def get_item_field_container(self, label: str) -> PageElement():
def get_item_field_container(self, label: str) -> PageElement:
label_node = self._soup.select_one(
f"div.item-object div.form-label:-soup-contains('{label}')"
f"div.data-field div.data-label:-soup-contains('{label}')"
)
if label_node:
return label_node.next_sibling
return None

def parse(self) -> Item:
id = self.try_extract_number(self._soup.select_one("a.current").text)
name = self._soup.select_one("span.h1-headline-value > span").text
thumbnail = self._soup.select_one("span.h1-headline-icon > img").get("src")
name = self.try_get_text("h1.title")
thumbnail = self.try_get_value("div.content-icon > img.thumbnail", "src")
category = get_item_category_from_str(
self.get_next_sibling_of("span.icon-tag").text
)
Expand Down

0 comments on commit 5a5586c

Please sign in to comment.