Browse Source

Fixes #34

master
Abrax 3 years ago
parent
commit
a7b4c4caf4
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      lizard/web_methods.py

+ 5
- 2
lizard/web_methods.py View File

@@ -50,7 +50,7 @@ def dump_thread_files(board, thread_no, thread_json):
file_url = generate_file_url(f['hashed_name'])
p = path_to_cached_file(board, thread_no, normalized)
if not download_file(file_url, p):
print('\t\tGot a 404, trying alternate link.')
print('\t\tAttempt failed, trying alternate link.')

# Try alternate link
alternate_url = generate_alternate_file_url(board, f['hashed_name'])
@@ -60,7 +60,7 @@ def dump_thread_files(board, thread_no, thread_json):
def download_file(file_url, file_path):
""" If the request succeeds, downloads the file and returns True.

On a 404, returns False. On other responses, raises exception. """
On a 404 or 504, returns False. On other responses, raises exception. """
r = requests.get(file_url, headers={'user-agent': user_agent})

if r.status_code == requests.codes.ok:
@@ -68,6 +68,9 @@ def download_file(file_url, file_path):
return True
elif r.status_code == 404:
return False
elif r.status_code == 504:
print("Server busy (504), couldn't get {}, try again later.".format(file_url))
return False
else:
raise RuntimeError("Unexpected status code {} while trying to fetch {} - try opening in the browser, if that doesn't work submit an issue to the tracker.".format(r.status_code, file_url))


Loading…
Cancel
Save