Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tumblr_backup: Stop if API responses stop making forward progress #219

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions tumblr_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ def _backup(posts):
# Get the JSON entries from the API, which we can only do for MAX_POSTS posts at once.
# Posts "arrive" in reverse chronological order. Post #0 is the most recent one.
i = options.skip
last_next_before = None
while True:
# find the upper bound
log(account, "Getting posts %d to %d (of %d expected)\r" % (i, i + MAX_POSTS - 1, count_estimate))
Expand All @@ -596,9 +597,19 @@ def _backup(posts):
continue

posts = _get_content(soup)
# `_backup(posts)` can be empty even when `posts` is not if we don't backup reblogged posts
if not posts or not _backup(posts):
log(account, "Backing up posts found empty set of posts, finishing\r")
if not posts:
log(account, "Found empty set of posts, finishing\r")
break

next_before = soup['response']['_links']['next']['query_params'].get('before')
if next_before is not None:
if next_before == last_next_before:
log(account, "Found same API response twice, finishing\r")
break
last_next_before = next_before

if not _backup(posts):
log(account, "Found last requested post, finishing\r")
break

i += MAX_POSTS
Expand Down