import os import configobj import wimcollect.common.logger as logger import wimcollect.common.utils as utils import wimcollect.common.ftp as ftp class Collector(utils.LogConfig): def __init__(self, config_parser: configobj.ConfigObj = None, log: logger = None): self.object_id = "FTPAERIS" utils.LogConfig.__init__(self, self.object_id, config_parser, log) self.distant_base_dir = self.config[self.object_id]["distant_base_dir"] def download_maido_mf_1h(self, yyyymm: str): """Download hourly monthly-released meteo data of Meteo-France's Maïdo station. Parameters ---------- yyyymm: str Year and month of the to-be-downloaded data """ self.logger.info("Download Maido's Meteo-France meteo data.", yyyymm) # Build source and destination file paths. source_filepath = self.distant_base_dir + "/" + "PMAIDO_1h_" + yyyymm + ".csv" dest_filepath = self.__get_dest_filepath__(yyyymm) # Download success = ftp.download_file(source_filepath, dest_filepath, self.logger, self.object_id, ftp_config=self.config[self.object_id]) # Compress if success: self.logger.info("Compressing ...", yyyymm) utils.compress_file(dest_filepath) self.logger.info("Done. Archive file: " + dest_filepath, yyyymm) def __get_dest_filepath__(self, yyyymm: str) -> str: # Build destination directory dest_dir = os.path.join(self.config["LOCAL"]["base_dir"], "REU", "meteo", "maidomf_1h") if not os.path.exists(dest_dir): os.makedirs(dest_dir) # Build destination filename filename = "REU_maidomf_" + yyyymm + ".csv" # Build full file path dest_filepath = os.path.join(dest_dir, filename) return dest_filepath