filemanager.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import os
  2. import logging
  3. import shutil
  4. from sim.config import Configuration
  5. import sim.utils.logconfig
  6. def move_file_to_server(df_name):
  7. _config = Configuration()
  8. _downloadFilePath = _config.DOWNLOAD_PATH
  9. _destinationBasePath = _config.SERVER_PATH
  10. _exts = [".pdf", ".xml"]
  11. _month = {
  12. '01': 'Enero',
  13. '02': 'Febrero',
  14. '03': 'Marzo',
  15. '04': 'Abril',
  16. '05': 'Mayo',
  17. '06': 'Junio',
  18. '07': 'Julio',
  19. '08': 'Agosto',
  20. '09': 'Septiembre',
  21. '10': 'Octubre',
  22. '11': 'Noviembre',
  23. '12': 'Diciembre'}
  24. logger = logging.getLogger(__name__)
  25. filepath = os.path.join(_downloadFilePath, df_name)
  26. #id = ecd_name.split("-")[0]
  27. #ecd_date = id.strip("SIN").strip("EC")
  28. df_date = df_name[:8]
  29. year = df_date[:4]
  30. month = df_date[4:6] + ' ' + _month[df_date[4:6]]
  31. for ext in _exts:
  32. file = filepath + ext
  33. dest_folder = os.path.join(_destinationBasePath, year, month, "Recibidas")
  34. #dest_folder = os.path.join(_destinationBasePath, ext.replace(".", "") + '_test', year, month)
  35. if not os.path.exists(dest_folder):
  36. logger.info(r"Creando el directorio {0} porque no existe".format(dest_folder))
  37. os.makedirs(dest_folder, exist_ok=True)
  38. if not os.path.exists(file):
  39. logger.debug("El archivo {0}{1} no existe".format(df_name, ext))
  40. else:
  41. logger.info("Copiando el archivo {0}{1} a su carpeta destino {2}".format(df_name, ext, dest_folder))
  42. shutil.copy(file, dest_folder)