This repository has been archived by the owner on May 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathprocessa_tabela_nbs.py
72 lines (57 loc) · 1.96 KB
/
processa_tabela_nbs.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
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import re
from converte_tabela_ibpt import cria_análises_ibpt, ibpt_para_nbs
CÓDIGO_NBS = re.compile(r'^1\.[0-9]{4}\.[0-9]{2}\.[0-9]{2}')
DESCRIÇÃO = ['', '', '']
def põe_descrição(texto):
texto = texto.strip()
if len(texto) and (texto[0].upper() == texto[0]):
DESCRIÇÃO.pop(0)
DESCRIÇÃO.pop(0)
DESCRIÇÃO.pop(0)
DESCRIÇÃO.append('')
DESCRIÇÃO.append('')
DESCRIÇÃO.append(texto)
else:
DESCRIÇÃO.pop(0)
DESCRIÇÃO.append(texto)
#print(texto, DESCRIÇÃO)
def _descrição():
ret = ' '.join(DESCRIÇÃO).strip().replace(' ', ' ')
DESCRIÇÃO.pop(0)
DESCRIÇÃO.pop(0)
DESCRIÇÃO.pop(0)
DESCRIÇÃO.append('')
DESCRIÇÃO.append('')
DESCRIÇÃO.append('')
return ret
if __name__ == '__main__':
cria_análises_ibpt()
arq = open('tabelas/nbs.txt', 'r', encoding='utf-8')
print('"NBS"|"DESCRIÇÃO"|"AL_IBPT_NACIONAL"|"AL_IBPT_INTERNACIONAL"')
#
# Guarda 3 linhas para a DESCRIÇÃO
#
código_anterior = ''
código = ''
terceira_linha = False
for linha in arq.readlines():
linha = linha.strip()
if terceira_linha:
põe_descrição(linha)
terceira_linha = False
ibpt = ibpt_para_nbs(código)
print('"%s"|"%s"|%s|%s' % (código, _descrição(), ibpt.al_nacional, ibpt.al_internacional))
if CÓDIGO_NBS.search(linha):
código = linha[0:12].replace('.', '')
desc = linha[12:].strip()
põe_descrição(desc)
ibpt = ibpt_para_nbs(código)
if desc == '' or desc[0].lower() == desc[0]:
terceira_linha = True
else:
print('"%s"|"%s"|%s|%s' % (código, _descrição(), ibpt.al_nacional, ibpt.al_internacional))
else:
põe_descrição(linha)
#print('"%s"|"%s"' % (código_anterior, _descrição()))
arq.close()