-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finished
filter_posts_with_indices
and add some other actions
- Loading branch information
Ljzd-PRO
committed
Nov 8, 2023
1 parent
4eeaf33
commit efb3341
Showing
4 changed files
with
106 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .base import * | ||
from .fetch import * | ||
from .job import * | ||
from .search import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import AsyncGenerator, List | ||
|
||
from ktoolbox.api.model import Post | ||
from ktoolbox.api.posts import get_creator_post | ||
from ktoolbox.api.utils import SEARCH_STEP | ||
from ktoolbox.utils import BaseRet | ||
|
||
__all__ = ["FetchInterruptError", "fetch_all_creator_posts"] | ||
|
||
|
||
class FetchInterruptError(Exception): | ||
"""Exception for interrupt of data fetching""" | ||
|
||
def __init__(self, *args, ret: BaseRet = None): | ||
super().__init__(*args) | ||
self.ret = ret | ||
|
||
|
||
async def fetch_all_creator_posts(service: str, creator_id: str) -> AsyncGenerator[List[Post]]: | ||
""" | ||
Fetch all posts from a creator | ||
:param service: The service where the post is located | ||
:param creator_id: The ID of the creator | ||
:return: Async generator of several list of posts | ||
:raise FetchInterruptError | ||
""" | ||
o = 0 | ||
while True: | ||
ret = await get_creator_post(service=service, creator_id=creator_id, o=o) | ||
if ret: | ||
yield ret.data | ||
if len(ret.data) < SEARCH_STEP: | ||
break | ||
else: | ||
o += SEARCH_STEP | ||
else: | ||
raise FetchInterruptError(ret=ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters