|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Literal, TypeAlias |
| 4 | + |
| 5 | +from linkedapi.types.base import LinkedApiModel |
| 6 | +from linkedapi.types.params import BaseActionParams, LimitParams |
| 7 | +from linkedapi.types.post import PostActorType, PostType |
| 8 | + |
| 9 | +PostSearchSort = Literal["topMatch", "latest"] |
| 10 | +PostSearchDatePosted = Literal["past24Hours", "pastWeek", "pastMonth"] |
| 11 | +PostSearchContentType = Literal["videos", "images", "jobPosts", "liveVideos", "documents"] |
| 12 | +PostSearchPostedBy = Literal["me", "firstConnections", "peopleYouFollow"] |
| 13 | + |
| 14 | + |
| 15 | +class SearchPostsPersonFilter(LinkedApiModel): |
| 16 | + """One person to narrow a post search by. |
| 17 | +
|
| 18 | + "name" is always required because LinkedIn's filter panel accepts nothing but typed text. The |
| 19 | + optional identifier decides which of the offered namesakes is taken; with "name" alone the pick |
| 20 | + is whichever suggestion LinkedIn ranked first. |
| 21 | + """ |
| 22 | + |
| 23 | + name: str |
| 24 | + urn: str | None = None |
| 25 | + person_hashed_url: str | None = None |
| 26 | + |
| 27 | + |
| 28 | +class SearchPostsCompanyFilter(LinkedApiModel): |
| 29 | + """One company to narrow a post search by. Same contract as SearchPostsPersonFilter.""" |
| 30 | + |
| 31 | + name: str |
| 32 | + urn: str | None = None |
| 33 | + company_hashed_url: str | None = None |
| 34 | + |
| 35 | + |
| 36 | +# A plain string is shorthand for the name alone: "Bill Gates" means {"name": "Bill Gates"}. |
| 37 | +# Both forms may be mixed in one list. |
| 38 | +SearchPostsPersonFilterEntry: TypeAlias = SearchPostsPersonFilter | str |
| 39 | +SearchPostsCompanyFilterEntry: TypeAlias = SearchPostsCompanyFilter | str |
| 40 | + |
| 41 | + |
| 42 | +class SearchPostsFilter(LinkedApiModel): |
| 43 | + """Filtering criteria for the LinkedIn content search. |
| 44 | +
|
| 45 | + Every specified field is applied, or the action fails. Ignored entirely when |
| 46 | + "custom_search_url" is specified. |
| 47 | + """ |
| 48 | + |
| 49 | + sort: PostSearchSort | None = None |
| 50 | + date_posted: PostSearchDatePosted | None = None |
| 51 | + content_type: PostSearchContentType | None = None |
| 52 | + posted_by: list[PostSearchPostedBy] | None = None |
| 53 | + from_members: list[SearchPostsPersonFilterEntry] | None = None |
| 54 | + from_companies: list[SearchPostsCompanyFilterEntry] | None = None |
| 55 | + mentioning_members: list[SearchPostsPersonFilterEntry] | None = None |
| 56 | + mentioning_companies: list[SearchPostsCompanyFilterEntry] | None = None |
| 57 | + author_companies: list[SearchPostsCompanyFilterEntry] | None = None |
| 58 | + author_industries: list[str] | None = None |
| 59 | + |
| 60 | + |
| 61 | +class SearchPostsParams(BaseActionParams, LimitParams): |
| 62 | + # Either "term" or "custom_search_url" must be provided. "limit" defaults to 10 and may go up |
| 63 | + # to 100, or up to 20 when child actions are attached. |
| 64 | + term: str | None = None |
| 65 | + filter: SearchPostsFilter | None = None |
| 66 | + custom_search_url: str | None = None |
| 67 | + |
| 68 | + |
| 69 | +class SearchPostActor(LinkedApiModel): |
| 70 | + """Whoever a search result attributes content to: its author, or the actor that reshared it. |
| 71 | +
|
| 72 | + Unlike the actors of a post returned by fetch_post, these carry no "urn": the URN is read from |
| 73 | + identity anchors on the post's own page, and a search result list has none of them. |
| 74 | + """ |
| 75 | + |
| 76 | + type: PostActorType | None = None |
| 77 | + name: str | None = None |
| 78 | + profile_url: str | None = None |
| 79 | + headline: str | None = None |
| 80 | + company_url: str | None = None |
| 81 | + |
| 82 | + |
| 83 | +class SearchPostResult(LinkedApiModel): |
| 84 | + url: str | None = None |
| 85 | + activity_urn: str | None = None |
| 86 | + time: str | None = None |
| 87 | + type: PostType | None = None |
| 88 | + author: SearchPostActor | None = None |
| 89 | + # Non-null only when "type" is "repost". |
| 90 | + reposter: SearchPostActor | None = None |
| 91 | + text: str | None = None |
| 92 | + repost_text: str | None = None |
| 93 | + hashtags: list[str] | None = None |
| 94 | + mentions: list[str] | None = None |
| 95 | + external_links: list[str] | None = None |
| 96 | + images: list[str] | None = None |
| 97 | + document_slides: list[str] | None = None |
| 98 | + has_video: bool | None = None |
| 99 | + video_thumbnail: str | None = None |
| 100 | + has_poll: bool | None = None |
| 101 | + reactions_count: int | None = None |
| 102 | + comments_count: int | None = None |
| 103 | + reposts_count: int | None = None |
0 commit comments