Commit 5fa61050 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

ftpopar. Use utils' compress_file() function.

parent 3de5db26
Pipeline #57063 passed with stages
in 53 seconds
......@@ -4,6 +4,7 @@ import datetime
import zipfile
import wimcollect.logger as logger
import wimcollect.utils as utils
import wimcollect.ftp as ftp
......@@ -27,11 +28,19 @@ class Collector(ftp.FtpCollector):
ftp_session = self._ftp_connect_()
source_filepath = self.base_dir + "/" + day.strftime("%Y%m%d") + "Meteo125HR.xls"
date_str = day.strftime("%Y%m%d")
# Build source and destination file paths
source_filepath = self.base_dir + "/" + date_str + "Meteo125HR.xls"
dest_filepath = self.__get_dest_filepath__(day)
# Download
success = self._ftp_download_file(ftp_session, source_filepath, dest_filepath)
# Compress
if success:
self.__compress_file__(day, dest_filepath)
self.logger.write(self.object_id, date_str + ": Compressing ...")
utils.compress_file(dest_filepath)
self.logger.write(self.object_id, date_str + ": Done. Archive file: " + dest_filepath)
ftp_session.quit()
......@@ -48,15 +57,3 @@ class Collector(ftp.FtpCollector):
dest_filepath = os.path.join(dest_dir, filename)
return dest_filepath
def __compress_file__(self, day: datetime.date, uncompressed_filepath: str):
# Compress the files
self.logger.write(self.object_id, day.strftime("%Y-%m-%d") + ": Compressing ...")
compressed_filepath = uncompressed_filepath + ".lzma"
zipf = zipfile.ZipFile(compressed_filepath, 'w', zipfile.ZIP_LZMA)
zipf.write(uncompressed_filepath, arcname=os.path.basename(uncompressed_filepath))
zipf.close()
if os.path.exists(compressed_filepath):
self.logger.write(self.object_id, day.strftime("%Y-%m-%d") + ": Done. Archive file: " + compressed_filepath)
os.remove(uncompressed_filepath)
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