-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
24 lines (15 loc) · 839 Bytes
/
Copy pathmain.py
File metadata and controls
24 lines (15 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Demo: consume a few articles; observe how few pages were fetched."""
from __future__ import annotations
import itertools
from patterns.behavioral.iterator.examples.paginated_client.backend import FakeBackend
from patterns.behavioral.iterator.examples.paginated_client.client import ArticleClient
def main() -> None:
backend = FakeBackend([f"article-{n:02d}" for n in range(30)], page_size=5)
client = ArticleClient(backend)
first_seven = list(itertools.islice(client.articles(), 7))
print(f"read {len(first_seven)} articles: {first_seven[0]} .. {first_seven[-1]}")
print(f"pages fetched: {backend.fetch_log} (30 articles = 6 pages exist)")
total = sum(1 for _ in client.articles())
print(f"full scan: {total} articles, pages fetched now: {backend.fetch_log}")
if __name__ == "__main__":
main()