Compare commits

..

2 Commits

  1. 38
      SyncReferences2IONOS/SyncReferences2IONOS.py

@ -61,7 +61,7 @@ def WriteToLog(referencia):
referencia = referencia.replace('[', '') referencia = referencia.replace('[', '')
referencia = referencia.replace(']', '') referencia = referencia.replace(']', '')
if referencia in processed_files: if referencia in processed_files:
print(f"El archivo {referencia} ya ha sido trabajada .") print(f"El archivo {referencia} ya ha sido procesado.")
return False return False
with open('./log/Referencias.txt', 'a') as f: with open('./log/Referencias.txt', 'a') as f:
@ -71,7 +71,7 @@ def WriteToLog(referencia):
log_file = "./log/fechayHora.txt" log_file = "./log/fechayHora.txt"
WriteToLogDate(log_file, referencia) WriteToLogDate(log_file, referencia)
print(f"El archivo {referencia} ha sido registrado en la carpeta Log en los respectivos archivos.") print(f"El archivo {referencia} ha sido registrado.")
return True return True
def CreateFolderContent(): def CreateFolderContent():
@ -92,10 +92,13 @@ def CreateFolderContent():
+ ";PWD=" + PasswordSIR + ";PWD=" + PasswordSIR
) )
cursor = cnxn.cursor() cursor = cnxn.cursor()
cursor.execute("""SELECT P.sReferencia, p.Archivo, P.Aduana, P.Patente, P.Pedimento, P.[Pedimento Fecha Pago], Peds.nTipoCambio, cursor.execute("""SELECT P.sReferencia, p.Archivo, P.Aduana, P.Patente, P.Pedimento, P.[Pedimento Fecha Pago], Peds.nTipoCambio, Res.sDescripcion,
P.Clave, P.Cliente FROM SIR.Admin.SIR_VT_PedimPagados P P.Clave, P.Cliente FROM SIR.Admin.SIR_VT_PedimPagados P
INNER JOIN SIR.SIR.SIR_149_PEDIMENTO AS Peds ON Peds.nIdPedimento149=ID INNER JOIN SIR.SIR.SIR_149_PEDIMENTO AS Peds ON Peds.nIdPedimento149=ID
WHERE P.ClienteClave=2096 and p.[Pedimento FechaPago]>=CAST( GETDATE()-5 AS Date ) """) INNER JOIN SIR.SIR.SIR_216_ARCHIVOS_PEDIMENTO A ON A.nIdArchM3216=Peds.nIdArchM3216
INNER JOIN SIR.SIR.SIR_217_PEDIMENTO_ARCHIVOM3 Rel on A.nIdArchM3216 = Rel.nIdArchM3216
INNER JOIN SIR.SIR.SIR_218_RESPUESTA_VALIDACION Res on Res.nIdArchM3216 = Rel.nIdArchM3216 AND Res.sDescripcion LIKE '%.err'
WHERE P.ClienteClave=2096 and p.[Pedimento FechaPago]>=CAST( GETDATE()-2 AS Date ) """)
for row in cursor: for row in cursor:
referencia = row[0] referencia = row[0]
archivoM = row[1] archivoM = row[1]
@ -104,19 +107,30 @@ def CreateFolderContent():
pedimento = row[4] pedimento = row[4]
fPago = row[5] fPago = row[5]
tipoCambio = row[6] tipoCambio = row[6]
clave = row[7] descripcion = row[7]
cliente = row [8] clave = row[8]
cliente = row[9]
referenceFolder = TempFolder + referencia referenceFolder = TempFolder + referencia
archivo_sDescripcion = os.path.join(referenceFolder, descripcion)
if referencia in processed_references: if referencia in processed_references:
print(f"La referencia {referencia} ya se ha trabajado.") print(f"La referencia {referencia} ya ha sido procesada.")
continue continue
if os.path.exists(referenceFolder): if os.path.exists(referenceFolder):
shutil.rmtree(referenceFolder) shutil.rmtree(referenceFolder)
shutil.copytree(RepositoryArchivoElectronicoOficial + str(YEAR) + '/' + referencia, referenceFolder) shutil.copytree(RepositoryArchivoElectronicoOficial + str(YEAR) + '/' + referencia, referenceFolder)
# Validar si el archivo sDescripcion existe en la carpeta del folder
if not os.path.isfile(archivo_sDescripcion):
print(f"El archivo {descripcion} no existe en la carpeta del folder para la referencia {referencia}. Proceso detenido.")
continue
zip_file = referenceFolder+'_____'+cliente+'.zip' zip_file = referenceFolder+'_____'+cliente+'.zip'
if os.path.exists(zip_file) == False: if os.path.exists(zip_file) == False:
ZipReference(referencia, referenceFolder, cliente) ZipReference(referencia, referenceFolder, cliente)
# Procesar archivo # Procesar archivo
if WriteToLog(referencia): if WriteToLog(referencia):
processed_references.append(referencia) processed_references.append(referencia)
@ -135,8 +149,8 @@ def CreateFolderContent():
'tipoCambio' : str(tipoCambio), 'tipoCambio' : str(tipoCambio),
'clave': clave 'clave': clave
} }
print( f"la referencia {referencia} esta siendo enviada al servidor." ) print( f"la referencia {referencia} ya ha sido posteada." )
r = requests.post(url=URL,files=multiple_files, verify=False, timeout=30) r = requests.post(url=URL,files=multiple_files, verify=False, timeout=1000)
except Exception as e: except Exception as e:
print("Error: %s" % e) print("Error: %s" % e)
# WriteToLog(r.text) # WriteToLog(r.text)
@ -144,3 +158,9 @@ def CreateFolderContent():
''' contents = [os.path.join(TempFolder, i) for i in os.listdir(TempFolder)] ''' contents = [os.path.join(TempFolder, i) for i in os.listdir(TempFolder)]
[shutil.rmtree(i) if os.path.isdir(i) and not os.path.islink(i) else os.remove(i) for i in contents] ''' [shutil.rmtree(i) if os.path.isdir(i) and not os.path.islink(i) else os.remove(i) for i in contents] '''
CreateFolderContent() CreateFolderContent()
#URL = 'https://www.gemcousa.mx/GEMCOBackend/api/AmazonInvoice/UploadSIRReference?ArchivoM=' +\
# URL = 'http://localhost:5000/api/AmazonInvoice/UploadSIRReference?ArchivoM=' +\
# URL 'https://www.gemcousa.solutions/GEMCOBackend/api/AmazonInvoice/UploadSIRReference?ArchivoM=' +\
Loading…
Cancel
Save