Advertisement
fransafu

init?

Aug 14th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8
  3.  
  4. import os
  5. import sys
  6. import xml.etree.ElementTree as ET
  7.  
  8.  
  9. def cargar_archivo(archivo):
  10.     ns = {'src': 'http://api.sbif.cl'}
  11.     arbol = ET.parse(archivo)
  12.     dolares = arbol.findall('src:Dolares', ns)[0].findall('src:Dolar', ns)
  13.  
  14.     resultado = []
  15.     for dolar in dolares:
  16.         fecha = dolar.find('src:Fecha', ns).text
  17.         valor = dolar.find('src:Valor', ns).text
  18.         resultado.append({'fecha': fecha,
  19.                           'valor': valor})
  20.  
  21.     return resultado
  22.  
  23. def listaArchivos():
  24.     path = os.getcwd() + '/Data_xml'
  25.     listaArchivo = []
  26.     listaDirectorio = os.walk(path) # Lista ficheros
  27.  
  28.     # Crea lista con los archivos encontrados en la carpeta Data_xml
  29.     for root, dirs, files in listaDirectorio:
  30.         for fichero in files:
  31.             (nombreFichero, extension) = os.path.splitext(fichero)
  32.             if(extension == ".xml"):
  33.                 listaArchivo.append(nombreFichero+extension)
  34.  
  35.     return listaArchivo
  36.  
  37. def main():
  38.     lista = listaArchivos()
  39.     for archivo in lista:
  40.         print cargar_archivo('Data_xml/' + archivo)
  41.  
  42. COMO ERA ESO DEL __INIT__()
  43. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement