hnx.models.items

Comment

Bases: Item

  • parent is the id of the parent item
  • text is the comment text
  • kids is the list of comment ids that are replies to this comment
Source code in hnx/models/items.py
32
33
34
35
36
37
38
39
40
41
42
43
class Comment(Item):
    """
    - `parent` is the id of the parent item
    - `text` is the comment text
    - `kids` is the list of comment ids that are replies to this comment
    """

    type: Literal[ItemType.COMMENT] = ItemType.COMMENT

    parent: int
    text: Optional[str] = None
    kids: list[int] = Field(default_factory=list)

Job

Bases: Item

  • modified story with no comments, for advertisement of job postings
Source code in hnx/models/items.py
46
47
48
49
50
51
52
53
54
55
class Job(Item):
    """
    - modified story with no comments, for advertisement of job postings
    """

    type: Literal[ItemType.JOB] = ItemType.JOB
    title: str
    score: int = 0
    text: Optional[str] = None
    url: Optional[str] = None

Poll

Bases: Item

  • title is the title of the poll
  • text
  • score
  • descendants is the total comment count
  • parts (items) is the list of poll option ids
  • kids is the list of comment ids that are replies to this poll
Source code in hnx/models/items.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class Poll(Item):
    """
    - `title` is the title of the poll
    - `text`
    - `score`
    - `descendants` is the total comment count
    - `parts` (items) is the list of poll option ids
    - `kids` is the list of comment ids that are replies to this poll
    """

    type: Literal[ItemType.POLL] = ItemType.POLL

    title: str
    text: Optional[str] = None

    score: int = 0

    descendants: int = 0
    kids: list[int] = Field(default_factory=list)
    parts: list[int] = Field(default_factory=list)

    def reply_count(self) -> int:
        return self.descendants

PollOption

Bases: Item

  • poll is the id of the poll this option belongs to.
  • score is the score of the poll option.
  • text is the text of the poll option.
Source code in hnx/models/items.py
83
84
85
86
87
88
89
90
91
92
93
94
class PollOption(Item):
    """
    - `poll` is the id of the poll this option belongs to.
    - `score` is the score of the poll option.
    - `text` is the text of the poll option.
    """

    type: Literal[ItemType.POLLOPTION] = ItemType.POLLOPTION

    poll: int
    score: int = 0
    text: str

Story

Bases: Item

  • title is the title of the story
  • url is the URL provided in the story, usually original src of the story
  • text
  • score
  • descendants is the total comment count
Source code in hnx/models/items.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Story(Item):
    """
    - `title` is the title of the story
    - `url` is the URL provided in the story, usually original src of the story
    - `text`
    - `score`
    - `descendants` is the total comment count
    """

    type: Literal[ItemType.STORY] = ItemType.STORY

    title: str
    url: Optional[str] = None
    text: Optional[str] = None

    score: int = 0

    descendants: int = 0
    kids: list[int] = Field(default_factory=list)

    def reply_count(self) -> int:
        return self.descendants

hnx.models.user

hnx.models.thread

CommentNode

Bases: BaseModel

Provider-agnostic comment tree node.

Source code in hnx/models/thread.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class CommentNode(BaseModel):
    """
    Provider-agnostic comment tree node.
    """

    model_config = ConfigDict(
        frozen=True,
    )

    id: int

    author: Optional[str] = None

    text: Optional[str] = None

    created_at: Optional[datetime] = None

    children: list["CommentNode"] = Field(default_factory=list)

    @property
    def reply_count(self) -> int:
        return len(self.children)

    @classmethod
    def from_algolia(
        cls,
        node: AlgoliaNode,
    ) -> "CommentNode":
        return cls(
            id=node.id,
            author=node.author,
            text=node.text,
            created_at=node.created_at,
            children=[cls.from_algolia(child) for child in node.children],
        )