]> git.ipfire.org Git - location/libloc.git/blobdiff - src/python/downloader.py
python: Fix download of database
[location/libloc.git] / src / python / downloader.py
index 5caad5188a4502b44a526638ca44135c1efe70cc..05f7872d1ff59b409c5c961e7362882c7d911888 100644 (file)
@@ -119,8 +119,8 @@ class Downloader(object):
 
                headers = {}
                if timestamp:
-                       headers["If-Modified-Since"] = timestamp.strftime(
-                               "%a, %d %b %Y %H:%M:%S GMT",
+                       headers["If-Modified-Since"] = time.strftime(
+                               "%a, %d %b %Y %H:%M:%S GMT", time.gmtime(timestamp),
                        )
 
                t = tempfile.NamedTemporaryFile(dir=tmpdir, delete=False)
@@ -180,6 +180,9 @@ class Downloader(object):
                                        # Return temporary file
                                        return t
 
+               # Delete the temporary file after unsuccessful downloads
+               os.unlink(t.name)
+
                raise FileNotFoundError(url)
 
        def _check_database(self, f, public_key, timestamp=None):
@@ -192,7 +195,7 @@ class Downloader(object):
                db = Database(f.name)
 
                # Database is not recent
-               if timestamp and db.created_at < timestamp.timestamp():
+               if timestamp and db.created_at < timestamp:
                        return False
 
                log.info("Downloaded new database from %s" % (time.strftime(