1
0

Removed excessive comparison of hash. Added message when file cannot be retrieved.

This commit is contained in:
Alexander Andreev 2021-05-04 03:56:59 +04:00
parent 0287d3a132
commit 419fb2b673
Signed by: Arav
GPG Key ID: 610DF2574456329F

View File

@ -110,11 +110,16 @@ class Scraper:
retries -= 1
else:
break
if retries == 0:
print(f"Cannot retrieve {f.download_url}, {filepath}.")
return
if is_same_filename:
f1_hexdig, f1_dig = self._hash_file(orig_filepath, f.hash_algorithm)
f2_hexdig, f2_dig = self._hash_file(filepath, f.hash_algorithm)
if f1_hexdig == f2_hexdig or f1_dig == f2_dig:
_, f1_dig = self._hash_file(orig_filepath, f.hash_algorithm)
_, f2_dig = self._hash_file(filepath, f.hash_algorithm)
if f1_dig == f2_dig:
remove(filepath)
except FileNotFoundError as e:
print("File Not Found", filepath)
except HTTPError as e:
print("HTTP Error", e.code, e.reason, f.download_url)
if exists(filepath):