In [ ]:
import json
from collections import namedtuple
In [ ]:
filejson = r'record_dump'
filejson = filejson if filejson.endswith('.json') else '{}.json'.format(filejson)
attrs = open(filejson).readlines()
lattrs = [json.loads(line.decode('utf-8')) for line in attrs]
In [ ]:
attr = [att['field'][1] for att in lattrs]
attr
In [ ]:
mpn = {mpn['field'][1]:mpn['field'][0] for mpn in lattrs}
mpn
In [ ]:
with open(r'C:\Python\MyTools\File-FixedS\record_dump.txt') as fi:
for row in fi:
print row
start = 0
for att in lattrs:
mp = 1
if att['sign']:
att['length'] = att['length'] + 1
print "att['field'][1]"
if mpn[att['field'][1]] != 'N':
print "mpn[att['field'][1]]", mpn[att['field'][1]]
mp = ord(row[start:start+1])
start += 1
att['length'] = att['length'] * mp
exec ("{} = slice({}, {})".format(att['field'][1], start, (start + att['length'])))
print att['field'][1], '-', eval("{}".format(att['field'][1]))
start += att['length']
In [ ]:
line = "02000000123412+000000123412+RSFLAVIO X"
tr = slice(0, 2, None)
valor = slice(3, 29, None)
estado = slice(29, 31, None)
nome = slice(31, 45, None)
In [ ]:
print line[0:2]
print line[3:29]
print line[29:31]
print line[31:45]
In [ ]:
fileIn = open(r'D:\Natural\PRODEB\DUMPs\XQ00B.C00.REORG.F135.DECOMP').readlines()
In [ ]:
len(fileIn)
In [ ]:
'OFZZZ'.decode('utf-8', 'ignore')
In [3]:
from unicodedata import normalize
ta = lambda txt: normalize('NFKD', txt.decode('UTF-8')).encode('ASCII', 'ignore')
In [4]:
ta('SIMÕES')
Out[4]:
In [1]:
'SIMÕES'.decode('utf-8', 'ignore')
Out[1]:
In [ ]: