Using glob in Python

2

I'm setting up a client that will play the files found in a folder to a WebService SOAP

This WebService has two methods that we will call MET1 and MET2 .

  • When the files found end in .XML and start with LCL, then I run MET1
  • When the files found end with .XML and start with CRC, then I run MET2

So far I've done this:

from zeep import Client
from xml.dom import minidom
import os
import glob


hasha = "9f56ccba6d88d2b089ab8a9fb40dd46f" 


for file in glob.glob('M:\SARA.VEMBU\TRACKING\SINERGIA\retorno\*.XML'):
    for file in glob.glob('M:\SARA.VEMBU\TRACKING\SINERGIA\retorno\LCL*'):
         arquivo = minidom.parse(file)
         arquivo = arquivo.toxml()
         arquivo = arquivo[22:]  

         client = Client('http://teste.php?wsdl')
         result = client.service.met1(arquivo, hasha)

         print(result.met1Response)

    for file in glob.glob('M:\SARA.VEMBU\TRACKING\SINERGIA\retorno\CRC*'):
         arquivo = minidom.parse(file)
         arquivo = arquivo.toxml()
         arquivo = arquivo[22:]  

         client = Client('http://teste.php?wsdl')
         result = client.service.met2(arquivo, hasha)

         print(result.met2Response)

But the code does not return anything, even the folder containing files with suffix and indicated prefix

Note: I'm a beginner in Python

    
asked by anonymous 03.04.2017 / 16:52

1 answer

0

Just do an if to see if the file starts with one or another start.

from zeep import Client
from xml.dom import minidom
import os
import glob

hasha = "9f56ccba6d88d2b089ab8a9fb40dd46f" 

for file in glob.glob('M:\SARA.VEMBU\TRACKING\SINERGIA\retorno\*.XML'):
    arquivo = minidom.parse(file)
    arquivo = arquivo.toxml()
    arquivo = arquivo[22:]  

    client = Client('http://teste.php?wsdl')

    filename = os.path.filename(file)

    if filename.startswith('LLC'):
        result = client.service.met1(arquivo, hasha)
        print(result.met1Response)
    else if filename.startswith('CRC'):
        result = client.service.met2(arquivo, hasha)
        print(result.met2Response) 
    
13.06.2017 / 01:36