fix: movie updates were not imported because of a broken timestamp

IMDb changed their exports. The timestamp of the file in their gzipped
export is now always 0, i.e. 1970-01-01T00:00:00Z.
This commit is contained in:
ducklet 2024-05-11 17:38:16 +02:00
parent 3ab5898f98
commit e9a58ed40e

View file

@ -101,12 +101,10 @@ title_types = {
}
def gz_mtime(path: Path) -> datetime:
"""Return the timestamp of the compressed file."""
g = gzip.GzipFile(path, "rb")
g.peek(1) # start reading the file to fill the timestamp field
assert g.mtime is not None
return datetime.fromtimestamp(g.mtime).replace(tzinfo=timezone.utc)
def _mtime(path: Path) -> datetime:
"""Return the timestamp of the file."""
mtime = path.stat().st_mtime
return datetime.fromtimestamp(mtime, tz=timezone.utc)
def count_lines(path: Path) -> int:
@ -160,7 +158,7 @@ def read_imdb_tsv(path: Path, row_type, *, unpack=True):
def read_ratings(path: Path):
mtime = gz_mtime(path)
mtime = _mtime(path)
rows = read_imdb_tsv(path, RatingRow)
for row in rows:
@ -176,7 +174,7 @@ def read_ratings_as_mapping(path: Path):
def read_basics(path: Path) -> Generator[Movie | None, None, None]:
mtime = gz_mtime(path)
mtime = _mtime(path)
rows = read_imdb_tsv(path, BasicRow)
for row in rows: