From eb2accc08895b6379fd00ed28c64fe978f13a09a Mon Sep 17 00:00:00 2001 From: Michel Ledig <71408872+Mesheo@users.noreply.github.com> Date: Wed, 17 Jul 2024 03:03:57 -0300 Subject: [PATCH] feat: add max_count parameter to limit posts on download (#2276) --- instaloader/instaloader.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index f94de9d..344f51c 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -1410,7 +1410,8 @@ class Instaloader: post_filter: Optional[Callable[[Post], bool]] = None, storyitem_filter: Optional[Callable[[Post], bool]] = None, raise_errors: bool = False, - latest_stamps: Optional[LatestStamps] = None): + latest_stamps: Optional[LatestStamps] = None, + max_count: Optional[int] = None): """High-level method to download set of profiles. :param profiles: Set of profiles to download. @@ -1427,6 +1428,7 @@ class Instaloader: Whether :exc:`LoginRequiredException` and :exc:`PrivateProfileNotFollowedException` should be raised or catched and printed with :meth:`InstaloaderContext.error_catcher`. :param latest_stamps: :option:`--latest-stamps`. + :param max_count: Maximum count of posts to download. .. versionadded:: 4.1 @@ -1435,6 +1437,9 @@ class Instaloader: .. versionchanged:: 4.8 Add `latest_stamps` parameter. + + .. versionchanged:: 4.13 + Add `max_count` parameter. """ @contextmanager @@ -1500,7 +1505,7 @@ class Instaloader: posts_to_download = profile.get_posts() self.posts_download_loop(posts_to_download, profile_name, fast_update, post_filter, total_count=profile.mediacount, owner_profile=profile, - takewhile=posts_takewhile, possibly_pinned=3) + takewhile=posts_takewhile, possibly_pinned=3, max_count=max_count) if latest_stamps is not None and posts_to_download.first_item is not None: latest_stamps.set_last_post_timestamp(profile_name, posts_to_download.first_item.date_local)