Skip to content

Commit

Permalink
Added support for cases where there is no Last-Modified header (e.g. …
Browse files Browse the repository at this point in the history
…testing)
  • Loading branch information
jake authored and jake committed Mar 25, 2024
1 parent fb9e653 commit 8fc9d19
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internetarchive/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,13 @@ def download(self, file_path=None, verbose=None, ignore_existing=None,
raise exc

# Get timestamp from Last-Modified header
time_str = response.headers["Last-Modified"]
last_updated_pattern = "%a, %d %b %Y %H:%M:%S %Z"
dt = datetime.strptime(time_str, last_updated_pattern).replace(tzinfo=timezone.utc)
last_modified = int(dt.timestamp())
try:
time_str = response.headers["Last-Modified"]
last_updated_pattern = "%a, %d %b %Y %H:%M:%S %Z"
dt = datetime.strptime(time_str, last_updated_pattern).replace(tzinfo=timezone.utc)
last_modified = int(dt.timestamp())
except KeyError:
last_modified = 0

# Set mtime with mtime from files.xml.
if not no_change_timestamp:
Expand Down

0 comments on commit 8fc9d19

Please sign in to comment.