From 071d9de1a59aff0e9984e64bd2cc060dcb257827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Mon, 10 Feb 2025 12:37:31 +0100 Subject: [PATCH] Avoid to redownload ban, as ban server does not respect If-Modified-Since --- bano/sources/ban.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bano/sources/ban.py b/bano/sources/ban.py index 6e66bca..8334279 100644 --- a/bano/sources/ban.py +++ b/bano/sources/ban.py @@ -43,12 +43,16 @@ def download(departement): ) id_batch = b.batch_start_log("download source", "BAN", departement) if resp.status_code == 200: - with destination.open("wb") as f: - f.write(resp.content) mtime = parsedate_to_datetime(resp.headers["Last-Modified"]).timestamp() - os.utime(destination, (mtime, mtime)) - b.batch_stop_log(id_batch, True) - return True + if mtime <= destination.stat().st_mtime: + b.batch_stop_log(id_batch, True) + return False + else: + with destination.open("wb") as f: + f.write(resp.content) + os.utime(destination, (mtime, mtime)) + b.batch_stop_log(id_batch, True) + return True if resp.status_code == 304: b.batch_stop_log(id_batch, True) return False