Skip to content

Feedly rss

FeedlyRssReader #

Bases: BaseReader

Feedly Rss阅读器。

从Feedly Rss阅读器获取条目

使用Feedly官方的python-api-client: https://github.com/feedly/python-api-client

Source code in llama_index/readers/feedly_rss/base.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class FeedlyRssReader(BaseReader):
    """Feedly Rss阅读器。

    从Feedly Rss阅读器获取条目

    使用Feedly官方的python-api-client: https://github.com/feedly/python-api-client"""

    def __init__(self, bearer_token: str) -> None:
        """使用参数进行初始化。"""
        super().__init__()
        self.bearer_token = bearer_token

    def setup_auth(
        self, directory: Path = Path.home() / ".config/feedly", overwrite: bool = False
    ):
        """修改自python-api-client/feedly/api_client/utils.py
不再提示用户输入,而是将令牌作为参数传递。
"""
        directory.mkdir(exist_ok=True, parents=True)

        auth_file = directory / "access.token"

        if not auth_file.exists() or overwrite:
            auth = self.bearer_token
            auth_file.write_text(auth.strip())

    def load_data(self, category_name, max_count=100):
        """从feedly类别中获取条目。"""
        from feedly.api_client.session import FeedlySession
        from feedly.api_client.stream import StreamOptions

        self.setup_auth(overwrite=True)
        sess = FeedlySession()
        category = sess.user.user_categories.get(category_name)

        documents = []
        for article in category.stream_contents(
            options=StreamOptions(max_count=max_count)
        ):
            # doc for available fields: https://developer.feedly.com/v3/streams/
            entry = {
                "title": article["title"],
                "published": article["published"],
                "summary": article["summary"],
                "author": article["author"],
                "content": article["content"],
                "keywords": article["keywords"],
                "commonTopics": article["commonTopics"],
            }

            text = json.dumps(entry, ensure_ascii=False)

            documents.append(Document(text=text))
        return documents

setup_auth #

setup_auth(
    directory: Path = Path.home() / ".config/feedly",
    overwrite: bool = False,
)

修改自python-api-client/feedly/api_client/utils.py 不再提示用户输入,而是将令牌作为参数传递。

Source code in llama_index/readers/feedly_rss/base.py
22
23
24
25
26
27
28
29
30
31
32
33
34
    def setup_auth(
        self, directory: Path = Path.home() / ".config/feedly", overwrite: bool = False
    ):
        """修改自python-api-client/feedly/api_client/utils.py
不再提示用户输入,而是将令牌作为参数传递。
"""
        directory.mkdir(exist_ok=True, parents=True)

        auth_file = directory / "access.token"

        if not auth_file.exists() or overwrite:
            auth = self.bearer_token
            auth_file.write_text(auth.strip())

load_data #

load_data(category_name, max_count=100)

从feedly类别中获取条目。

Source code in llama_index/readers/feedly_rss/base.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def load_data(self, category_name, max_count=100):
    """从feedly类别中获取条目。"""
    from feedly.api_client.session import FeedlySession
    from feedly.api_client.stream import StreamOptions

    self.setup_auth(overwrite=True)
    sess = FeedlySession()
    category = sess.user.user_categories.get(category_name)

    documents = []
    for article in category.stream_contents(
        options=StreamOptions(max_count=max_count)
    ):
        # doc for available fields: https://developer.feedly.com/v3/streams/
        entry = {
            "title": article["title"],
            "published": article["published"],
            "summary": article["summary"],
            "author": article["author"],
            "content": article["content"],
            "keywords": article["keywords"],
            "commonTopics": article["commonTopics"],
        }

        text = json.dumps(entry, ensure_ascii=False)

        documents.append(Document(text=text))
    return documents