Guest User

Untitled

a guest
Jul 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. from xml.dom.minidom import parse
  2. import os
  3. import sys
  4.  
  5.  
  6. def main():
  7. if len(sys.argv) < 2:
  8. exit('Usage: sum.py folder-with-xmls')
  9.  
  10. dirname = sys.argv[1]
  11.  
  12. if not os.path.isdir(dirname):
  13. exit('argument must be a directory')
  14.  
  15. total = 0.0
  16.  
  17. for filename in os.listdir(dirname):
  18. if not filename.endswith('.xml'):
  19. continue
  20.  
  21. dom = parse(os.path.join(dirname, filename))
  22.  
  23. print(dom.getElementsByTagName('cfdi:Comprobante')[0].getAttribute('Fecha'))
  24.  
  25. for item in dom.getElementsByTagName('cfdi:Concepto'):
  26. print('\t{}…: {}x{}'.format(
  27. item.getAttribute('Descripcion')[:15],
  28. item.getAttribute('ValorUnitario'),
  29. item.getAttribute('Cantidad'),
  30. ))
  31.  
  32. for tax in item.getElementsByTagName('cfdi:Traslado'):
  33. amount = float(tax.getAttribute('Importe'))
  34.  
  35. print('\t\t{}'.format(amount))
  36. total += amount
  37.  
  38. print(total)
  39.  
  40.  
  41. if __name__ == '__main__':
  42. main()
Add Comment
Please, Sign In to add comment