-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcte.py
47 lines (39 loc) · 1.41 KB
/
cte.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob
from lxml import objectify
def formatdate(date):
date = date.split('T')
date = date[0].split('-')
date = date[2]+date[1]+date[0]
return date
sped = dict()
part_list = []
cte_list = []
arq = open('1.txt', 'r')
texto = arq.readlines()
for line in texto:
line_split = line.split("|")
if line_split[1] not in sped:
sped[line_split[1]] = []
sped[str(line_split[1])].append(line)
arq.close()
for file in glob.glob('cte/*.xml'):
arq = open(file, 'r')
texto = arq.read()
texto = texto.encode('utf-8')
arq.close()
cte = objectify.fromstring(texto)
participante = "|0150|" + str(cte.cteProc.CTe.infCte.emit.CNPJ) + "|" + \
str(cte.cteProc.CTe.infCte.emit.xNome) + "|" + "1058|" + \
str(cte.cteProc.CTe.infCte.emit.CNPJ) + "||" + \
str(cte.cteProc.CTe.infCte.emit.IE) + "|" + \
str(cte.cteProc.CTe.infCte.emit.enderEmit.cMun) + "||" + \
str(cte.cteProc.CTe.infCte.emit.enderEmit.xLgr) + "|" + \
str(cte.cteProc.CTe.infCte.emit.enderEmit.nro) + "|"
if hasattr(cte.cteProc.CTe.infCte.emit.enderEmit, 'xCpl'):
participante = participante + str(cte.cteProc.CTe.infCte.emit.enderEmit.xCpl) + "|"
else:
participante = participante + "|"
participante = participante + str(cte.cteProc.CTe.infCte.emit.enderEmit.xBairro) + "|"
sped['0150'].append(participante)