1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-11-04 17:32:30 +01:00

Nicer syntax for resumable_iteration usage

This commit is contained in:
Alexander Graf 2020-08-02 10:22:45 +02:00
parent c71873231d
commit a8d3851956
2 changed files with 6 additions and 8 deletions

View File

@ -758,17 +758,16 @@ class Instaloader:
), ),
check_bbd=self.check_resume_bbd, check_bbd=self.check_resume_bbd,
enabled=self.resume_prefix is not None enabled=self.resume_prefix is not None
) as resume_info: ) as (is_resuming, start_index):
is_resuming, start_index = resume_info for number, post in enumerate(posts, start=start_index + 1):
for number, post in enumerate(posts): if max_count is not None and number > max_count:
if max_count is not None and number + start_index >= max_count:
break break
if displayed_count is not None: if displayed_count is not None:
self.context.log("[{0:{w}d}/{1:{w}d}] ".format(number + start_index + 1, displayed_count, self.context.log("[{0:{w}d}/{1:{w}d}] ".format(number, displayed_count,
w=len(str(displayed_count))), w=len(str(displayed_count))),
end="", flush=True) end="", flush=True)
else: else:
self.context.log("[{:3d}] ".format(number + start_index + 1), end="", flush=True) self.context.log("[{:3d}] ".format(number), end="", flush=True)
if post_filter is not None: if post_filter is not None:
try: try:
if not post_filter(post): if not post_filter(post):

View File

@ -219,8 +219,7 @@ def resumable_iteration(context: InstaloaderContext,
load=lambda _, path: FrozenNodeIterator(**json.load(open(path))), load=lambda _, path: FrozenNodeIterator(**json.load(open(path))),
save=lambda fni, path: json.dump(fni._asdict(), open(path, 'w')), save=lambda fni, path: json.dump(fni._asdict(), open(path, 'w')),
format_path=lambda magic: "resume_info_{}.json".format(magic) format_path=lambda magic: "resume_info_{}.json".format(magic)
) as resume_info: ) as (is_resuming, start_index):
is_resuming, start_index = resume_info
for post in post_iterator: for post in post_iterator:
do_something_with(post) do_something_with(post)