Commit 4eb916cd authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

HTTPDDU. Use new logger functions.

parent 066fc8c4
Pipeline #57318 passed with stages
in 1 minute and 12 seconds
......@@ -13,7 +13,7 @@ class Collector(utils.LogConfig):
utils.LogConfig.__init__(self, "HTTPDDU", config_parser, log)
self.base_url = self.config[self.object_id]["base_url"]
def download_picarro(self, picarro_id: str, day: datetime.date):
def download_picarro(self, picarro_id: str, day: datetime.date) -> bool:
"""Download Picarro data file from IPEV's HTTP server.
Parameters
......@@ -32,25 +32,21 @@ class Collector(utils.LogConfig):
dest_filepath = self.__get_dest_filepath__(picarro_id, day, source_fileurl)
# Download file
self.logger.write(self.object_id, "[" + day_str + "] Downloading DDU Picarro file from " + source_fileurl)
self.logger.info("Downloading DDU Picarro file from " + source_fileurl, day_str)
response = urllib.request.urlretrieve(source_fileurl, dest_filepath)
success = response[0] == dest_filepath and os.path.exists(dest_filepath)
if not success:
msg = "[" + day_str + "] FAILED to download file."
self.logger.write(self.object_id, msg)
raise Exception(msg)
self.logger.error("FAILED to download file in " + dest_filepath, day_str)
else:
self.logger.write(self.object_id, "[" + day_str + "] File downloaded in " + dest_filepath)
self.logger.info("File downloaded in " + dest_filepath, day_str)
# Recompress file, from ZIP to LZMA
self.logger.write(self.object_id, "[" + day_str + "] Re-compressing from ZIP to LZMA...")
self.logger.info("Re-compressing from ZIP to LZMA...", day_str)
lzma_filepath = utils.recompress_file(dest_filepath)
if lzma_filepath is None:
msg = "[" + day_str + "] FAILED to create archive file"
self.logger.write(self.object_id, msg)
return False
self.logger.error("FAILED to re-compress " + dest_filepath, day_str)
else:
self.logger.write(self.object_id, "[" + day_str + "] Done. Archive file: " + lzma_filepath)
self.logger.info("Done. Archive file: " + lzma_filepath, day_str)
return True
def __get_dest_filepath__(self, picarro_id: str, day: datetime.date, source_filepath: str) -> str:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment