Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.dom.minidom import parse
- import os
- import sys
- def main():
- if len(sys.argv) < 2:
- exit('Usage: sum.py folder-with-xmls')
- dirname = sys.argv[1]
- if not os.path.isdir(dirname):
- exit('argument must be a directory')
- total = 0.0
- for filename in os.listdir(dirname):
- if not filename.endswith('.xml'):
- continue
- dom = parse(os.path.join(dirname, filename))
- print(dom.getElementsByTagName('cfdi:Comprobante')[0].getAttribute('Fecha'))
- for item in dom.getElementsByTagName('cfdi:Concepto'):
- print('\t{}…: {}x{}'.format(
- item.getAttribute('Descripcion')[:15],
- item.getAttribute('ValorUnitario'),
- item.getAttribute('Cantidad'),
- ))
- for tax in item.getElementsByTagName('cfdi:Traslado'):
- amount = float(tax.getAttribute('Importe'))
- print('\t\t{}'.format(amount))
- total += amount
- print(total)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment