| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import os
- import logging
- import shutil
- from sim.config import Configuration
- import sim.utils.logconfig
- def move_file_to_server(df_name):
- _config = Configuration()
- _downloadFilePath = _config.DOWNLOAD_PATH
- _destinationBasePath = _config.SERVER_PATH
- _exts = [".pdf", ".xml"]
- _month = {
- '01': 'Enero',
- '02': 'Febrero',
- '03': 'Marzo',
- '04': 'Abril',
- '05': 'Mayo',
- '06': 'Junio',
- '07': 'Julio',
- '08': 'Agosto',
- '09': 'Septiembre',
- '10': 'Octubre',
- '11': 'Noviembre',
- '12': 'Diciembre'}
- logger = logging.getLogger(__name__)
- filepath = os.path.join(_downloadFilePath, df_name)
- #id = ecd_name.split("-")[0]
- #ecd_date = id.strip("SIN").strip("EC")
- df_date = df_name[:8]
- year = df_date[:4]
- month = df_date[4:6] + ' ' + _month[df_date[4:6]]
- for ext in _exts:
- file = filepath + ext
- dest_folder = os.path.join(_destinationBasePath, year, month, "Recibidas")
- #dest_folder = os.path.join(_destinationBasePath, ext.replace(".", "") + '_test', year, month)
- if not os.path.exists(dest_folder):
- logger.info(r"Creando el directorio {0} porque no existe".format(dest_folder))
- os.makedirs(dest_folder, exist_ok=True)
- if not os.path.exists(file):
- logger.debug("El archivo {0}{1} no existe".format(df_name, ext))
- else:
- logger.info("Copiando el archivo {0}{1} a su carpeta destino {2}".format(df_name, ext, dest_folder))
- shutil.copy(file, dest_folder)
|