feat: pagination_iterator関数を追加

feat/add-sphinx-doc
yupix 1 year ago
parent 1106d94860
commit edcd4b65a5
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -1,8 +1,15 @@
from typing import Any, Generic, Literal, TypeVar
from __future__ import annotations
from typing import TYPE_CHECKING, Any, AsyncGenerator, Generic, Literal, Type, TypeVar
from mipac.abstract.model import AbstractModel
from mipac.http import HTTPClient, Route
if TYPE_CHECKING:
from mipac.manager.client import ClientManager
T = TypeVar("T")
M = TypeVar("M", bound=AbstractModel)
class Pagination(Generic[T]):
@ -64,3 +71,14 @@ class Pagination(Generic[T]):
if self.pagination_type == "until" and self.latest_res_count == 0:
return True
return False
async def pagination_iterator(
pagination: Pagination, get_all: bool = False, *, model: Type[M], client: ClientManager
) -> AsyncGenerator[M, None]:
while True:
res = await pagination.next()
for i in res:
yield model(i, client=client)
if pagination.is_final or get_all is False:
break

Loading…
Cancel
Save