File size: 791 Bytes
6cfe55f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Protocol


@dataclass
class ArticleContent:
    platform: str
    url: str
    article_id: str
    title: str
    author_name: str = ""
    author_id: str = ""
    content_text: str = ""
    image_urls: list[str] = field(default_factory=list)
    cover_url: str = ""
    published_at: str = ""
    raw_metadata: dict = field(default_factory=dict)


class ArticleFetchError(Exception):
    pass


class ArticleFetcher(Protocol):
    platform: str

    def fetch(self, url: str) -> ArticleContent:
        ...

    def search(self, keyword: str, limit: int = 20) -> list[ArticleContent]:
        ...

    def fetch_publisher(self, query: str, limit: int = 20) -> list[ArticleContent]:
        ...