Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys
- # coding=utf8
- # PafKit
- # Jent Software
- # Copyright 2016
- errors = 0
- lines = 0
- print("\x1b[2J\x1b[1;1H") # Limpa a tela
- print("Pafkit analisa o arquivo do anexo IV do seu PAF-ECF\nVersão 0.1\n<<< Renomeie o arquivo a ser analisado para \"anexoIV.txt\" >>>\nJent Software - www.jent.com.br\n\n")
- # Opening the file
- fileObject = open('/home/jent/projects/PafKit/anexoIV.txt', 'r')
- # INSERIR AQUI OS TRATAMENTOS NO CASO DO ARQUIVO NÃO ABRIR
- fileRead = fileObject.read()
- fileRead = fileRead.upper() # This uppers the string
- # Separating lines
- fileReadSplitted = (fileRead.split('\n')) # This separate all lines of the file
- if not fileObject.read(0): #This line provides a mechanism that denies empty files
- print("Erro fatal: arquivo vazio. Análise abortada. (F02)\n")
- sys.exit()
- #Counting the number of lines
- for currLine in fileObject:
- lines += 1
- # Registro do tipo U1
- def U1func():
- global errors
- if not fileReadSplitted[0].startswith('U1'):
- print("Erro fatal: Registro do tipo U1 não está presente no arquivo. Não é possível prosseguir com a análise. (F01)\n")
- sys.exit()
- elif not fileReadSplitted[0][2:15].isdecimal():
- print('Linha ' + str(fileReadSplitted[0]))
- print('Erro: O CNPJ ' + str(fileReadSplitted[0][2:15]) + ' não é composto exclusivamente por caracteres decimais. (U01)\n')
- errors += 1
- def countErrors():
- if errors > 0:
- print('Erros encontrados: ' + str(errors))
- elif errors == 0:
- print('Não foram encontrados erros na análise deste arquivo!')
- U1func()
- countErrors()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement