Skip to content

Commit

Permalink
tumblr_backup: Clearly explain why the backup stopped
Browse files Browse the repository at this point in the history
This is especially helpful if less posts were backed up than the user
expected.
  • Loading branch information
cebtenzzre committed Oct 16, 2020
1 parent 7d19743 commit 623c7a4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tumblr_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,14 @@ def _backup(posts, post_respfiles):
if ident_max is None:
pass # No limit
elif (p['timestamp'] if options.likes else long(post.ident)) <= ident_max:
return False
if options.count and self.post_count >= options.count:
log('Stopping backup: Incremental backup complete\n', account=True)
return False
if options.period:
if post.date >= options.p_stop:
raise RuntimeError('Found post with date ({}) older than before param ({})'.format(
post.date, options.p_stop))
if post.date < options.p_start:
log('Stopping backup: Reached end of period\n', account=True)
return False
if options.request:
if post.typ not in options.request:
Expand All @@ -837,6 +837,9 @@ def _backup(posts, post_respfiles):

backup_pool.add_work(post.save_content)
self.post_count += 1
if options.count and self.post_count >= options.count:
log('Stopping backup: Reached limit of {} posts\n'.format(options.count), account=True)
return False
return True

try:
Expand All @@ -856,19 +859,20 @@ def _backup(posts, post_respfiles):
break

posts = resp[posts_key]
if not posts:
log('Backup complete: Found empty set of posts\n', account=True)
break

post_respfiles = resp.get('post_respfiles')
if post_respfiles is None:
post_respfiles = [None for _ in posts]

# `_backup(posts)` can be empty even when `posts` is not if we don't backup reblogged posts
if not posts or not _backup(posts, post_respfiles):
log.status('Backing up posts found empty set of posts, finishing\r')
if not _backup(posts, post_respfiles):
break

if options.likes:
next_ = resp['_links'].get('next')
if next_ is None:
log.status('Backing up posts found end of likes, finishing\r')
log('Backup complete: Found end of likes\n', account=True)
break
before = next_['query_params']['before']
i += MAX_POSTS
Expand Down

0 comments on commit 623c7a4

Please sign in to comment.