From ce287e9493a077203609f1ecfdca33e98b30c735 Mon Sep 17 00:00:00 2001
From: Jomaro <jomaro.rodrigues@gmail.com>
Date: Tue, 27 Oct 2015 18:10:01 -0200
Subject: [PATCH] =?UTF-8?q?metade=20da=20corre=C3=A7=C3=A3o=20do=20problem?=
 =?UTF-8?q?a=20das=20colunas?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 adega_crypt.py | 62 ++++++++++++++++++++++++++++++++++++++++++++------
 check.py       |  3 +++
 2 files changed, 58 insertions(+), 7 deletions(-)
 mode change 100644 => 100755 check.py

diff --git a/adega_crypt.py b/adega_crypt.py
index 9e688d0..0944da4 100755
--- a/adega_crypt.py
+++ b/adega_crypt.py
@@ -6,6 +6,8 @@ import sys
 import pandas as pd
 import numpy as np
 import os
+import shutil
+import re
 
 
 
@@ -35,8 +37,40 @@ $ %s -d relatorio.csv
 
 
 def crypt(name):
+	
+	notify_empty_lines = False
+	notify_comma_decimal_separator = False
+	
+	if not os.path.exists('.'+name):
+		shutil.copyfile(name, '.'+name)
+	else:
+		print('arquivo .%s ja existe, abortando' % name)
+		sys.exit(1)
+	
+	comma_separator = re.compile(ur',33333333|,66666666')
+	
+	orig = open(name, 'r')
+	rep = open('.'+name, 'w+')
+	
+	for line in orig:
+		if len(line) == 0:
+			notify_empty_lines = True
+		elif comma_separator.search(line):
+			notify_comma_decimal_separator = True
+			
+			#l = line.decode('utf8').replace(r',33333333', r'.33333333').replace(r',66666666', r'.66666666').encode('utf8')
+			l = line.replace(r',33333333', r'.33333333').replace(r',66666666', r'.66666666')
+			
+			rep.write(l)
+		else:
+			rep.write(line)
+	
+	orig.close()
+	rep.close()
+	
+	#sys.exit(5)
 
-	data = pd.read_csv(name)
+	data = pd.read_csv('.'+name)
 	
 	if os.path.exists(TABLE_FILE):
 		table = pd.read_csv(TABLE_FILE)
@@ -46,7 +80,7 @@ def crypt(name):
 		if not os.path.exists(dirname):
 			os.makedirs(dirname)
 		
-		table = pd.DataFrame(columns=["ID", "MATR_ALUNO", "NOME_ALUNO"])
+		table = pd.DataFrame(columns=["ID", "MATR_ALUNO", "NOME_PESSOA"])
 		table.to_csv(TABLE_FILE, index=False)
 		
 
@@ -63,15 +97,18 @@ def crypt(name):
 	#
 	
 	if "NOME_ALUNO" in data.columns:
+		data.rename(columns={'NOME_ALUNO': 'NOME_PESSOA'}, inplace=True)
+	
+	if "NOME_PESSOA" in data.columns:
 		
-		table_append = pd.merge(table_append, data[["MATR_ALUNO", "NOME_ALUNO"]], how="left", on="MATR_ALUNO")
+		table_append = pd.merge(table_append, data[["MATR_ALUNO", "NOME_PESSOA"]], how="left", on="MATR_ALUNO")
 		
 		UTF8toupper = lambda s: s.decode("utf8").upper().encode("utf8")
 		
-		table_append["NOME_ALUNO"] = table_append.NOME_ALUNO.apply(UTF8toupper)
+		table_append["NOME_PESSOA"] = table_append.NOME_PESSOA.apply(UTF8toupper)
 		
 	else:
-		table_append["NOME_ALUNO"] = ""
+		table_append["NOME_PESSOA"] = ""
 	
 	
 	# pega todos os registros que ainda não existem no table
@@ -106,8 +143,8 @@ def crypt(name):
 	
 	del data["MATR_ALUNO"]
 	
-	if "NOME_ALUNO" in data.columns:
-		del data["NOME_ALUNO"]
+	if "NOME_PESSOA" in data.columns:
+		del data["NOME_PESSOA"]
 	
 	data.rename(columns={"ID": "MATR_ALUNO"}, inplace=True)
 	
@@ -129,6 +166,17 @@ def crypt(name):
 	# escreve o arquivo
 	#
 	data.to_csv(".".join(split_name), index=False)
+	
+	os.remove('.'+name)
+	
+	if notify_empty_lines or notify_comma_decimal_separator:
+		print "Warnings:"
+		
+	if notify_empty_lines:
+		print "Linha em branco presente no arquivo"
+		
+	if notify_comma_decimal_separator:
+		print "virgula foi usada como separador de campo decimal"
 
 	return data
 
diff --git a/check.py b/check.py
old mode 100644
new mode 100755
index 21ecc5f..4b60ae3
--- a/check.py
+++ b/check.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# coding: utf-8
+
 import pandas as pd
 import os
 
-- 
GitLab