-
Notifications
You must be signed in to change notification settings - Fork 1
/
factur-O-meter.py
59 lines (49 loc) · 1.63 KB
/
factur-O-meter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: cp1252 -*-
from xml.dom import minidom
from xml.dom.minidom import parseString
import glob
def parseXML():
for file in GetXML():
xmldoc = minidom.parse(file)
itemlist = xmldoc.getElementsByTagName('cfdi:Comprobante')
fact=Factura()
for s in itemlist :
try:
fact.Folio=s.attributes['folio'].value
except:
fact.Folio=""
fact.LugarExpedicion=s.attributes['LugarExpedicion'].value
fact.Total=s.attributes['total'].value
itemlist = xmldoc.getElementsByTagName('cfdi:Receptor')
for s in itemlist :
fact.RFC=s.attributes['rfc'].value
fact.Nombre= s.attributes['nombre'].value
AgregoArchivo(fact)
def GetXML():
files=[]
for file in glob.glob("xml/*.xml"):
files.append(file)
print file
return files
def AgregoArchivo(factura):
SEPARADOR=";"
with open('FacturasCaro.csv', 'a') as the_file:
the_file.write(factura.Folio.encode('utf8'))
the_file.write(SEPARADOR)
the_file.write(factura.RFC.encode('utf8') )
the_file.write(SEPARADOR)
the_file.write(factura.Nombre.encode('utf8') )
the_file.write(SEPARADOR)
the_file.write(factura.LugarExpedicion.encode('utf8') )
the_file.write(SEPARADOR)
the_file.write(factura.Total)
the_file.write(SEPARADOR)
the_file.write('\n')
class Factura:
Folio=""
LugarExpedicion=""
Nombre=""
RFC=""
Total=""
if __name__ == "__main__":
parseXML()