From d358ba26e43912ea2566a03fdbbdf2295fa25d44 Mon Sep 17 00:00:00 2001
From: Cristian Weiland <cw14@inf.ufpr.br>
Date: Tue, 7 Feb 2017 09:49:12 -0200
Subject: [PATCH] Add scripts to help inserting data and fix bug inserting null
 values

Signed-off-by: Cristian Weiland <cw14@inf.ufpr.br>
---
 .gitignore                                   |  1 +
 README                                       | 15 ++--
 add_registers.sh                             | 52 ++++++++++++++
 configs/config-2016-01.json                  | 16 -----
 configs/config-2016-02.json                  | 16 -----
 configs/config-2016-03.json                  | 16 -----
 configs/config-2016-04.json                  | 16 -----
 configs/config-2016-05.json                  | 16 -----
 configs/config-2016-06.json                  | 16 -----
 configs/config-2016-07.json                  | 16 -----
 configs/config-2016-08.json                  | 16 -----
 configs/config-2016-09.json                  | 16 -----
 configs/config-2016-10.json                  | 16 -----
 configs/config-2016-11.json                  | 16 -----
 configs/generate_config.sh                   |  6 --
 insert_data.sh => insert_resgiter_payment.sh |  0
 logstash_config.example                      |  2 +-
 merge_files_es.py                            | 11 ++-
 scripts/expenses/process_expenses.sh         | 76 ++++++++++++++++++++
 scripts/expenses/resume_expenses.sh          | 25 +++++++
 scripts/expenses/unzip.sh                    |  9 +++
 scripts/expenses/unzipCaller.sh              | 66 +++++++++++++++++
 22 files changed, 245 insertions(+), 194 deletions(-)
 create mode 100755 add_registers.sh
 delete mode 100644 configs/config-2016-01.json
 delete mode 100644 configs/config-2016-02.json
 delete mode 100644 configs/config-2016-03.json
 delete mode 100644 configs/config-2016-04.json
 delete mode 100644 configs/config-2016-05.json
 delete mode 100644 configs/config-2016-06.json
 delete mode 100644 configs/config-2016-07.json
 delete mode 100644 configs/config-2016-08.json
 delete mode 100644 configs/config-2016-09.json
 delete mode 100644 configs/config-2016-10.json
 delete mode 100644 configs/config-2016-11.json
 delete mode 100644 configs/generate_config.sh
 rename insert_data.sh => insert_resgiter_payment.sh (100%)
 create mode 100755 scripts/expenses/process_expenses.sh
 create mode 100755 scripts/expenses/resume_expenses.sh
 create mode 100755 scripts/expenses/unzip.sh
 create mode 100755 scripts/expenses/unzipCaller.sh

diff --git a/.gitignore b/.gitignore
index ef9ffce..074d019 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 Dados_Servidores
 logstash_configs
 configs
+Favorecidos
diff --git a/README b/README
index 64ac6cc..ee645d2 100644
--- a/README
+++ b/README
@@ -3,16 +3,15 @@ Projeto utilizando ElasticSearch + Kibana na tentativa de auxiliar a transparên
 Árvore de Diretórios:
 
 .
-├── Dados\_Servidores - Contém uma diretório para cada mês.
+├── Dados_Servidores - Contém uma diretório para cada mês.
 │   ├── 2016-12 - Diretório que contém os CSVs referentes a Dezembro de 2016.
 │   ├── 2016-11 - Diretório que contém os CSVs referentes a Novembro de 2016.
 │   ├── ...
 │   └── Processados - Diretório que contém CSVs resultantes da união de CSVs do portal transparência.
-├── configs - Diretório com arquivos de configuração para unir CSVs do portal transparência em um só, que é inserido no Kibana/ElasticSearch.
 ├── config.json.example - Exemplo de arquivo do diretório 'configs'.
-├── logstash\_configs - Diretório com arquivos de configuração do Logstash para inserção de dados no Kibana/ElasticSearch.
-├── logstash\_config.example - Exemplo de arquivo do diretório 'logstash\_configs'. É usado pelo script 'create\_config.py' para gerar o arquivo de configuração do logstash.
-├── create\_config.py - Script que cria arquivos de configuração que ficam contidos nos diretórios 'configs' e 'logstash\_configs'.
-├── resumo\_cadastro.sh - Script que filtra dados do CSV de Cadastro do Portal Transparência, selecionando dados das Universidades interessantes para este projeto.
-├── merge\_files\_es.py - Script que usa um arquivo de configuração do diretório 'configs' para unir dois CSVs (Cadastro e Remuneração) do portal transparência em um só e salvá-lo no diretório Dados\_Servidores/Processados
-└── insert\_data.sh - Script que gerencia os outros scripts.
+├── logstash_configs - Diretório com arquivos de configuração do Logstash para inserção de dados no Kibana/ElasticSearch.
+├── logstash_config.example - Exemplo de arquivo do diretório 'logstash_configs'. É usado pelo script 'create_config.py' para gerar o arquivo de configuração do logstash.
+├── create_config.py - Script que cria arquivos de configuração que ficam contidos nos diretórios 'configs' e 'logstash_configs'.
+├── resumo_cadastro.sh - Script que filtra dados do CSV de Cadastro do Portal Transparência, selecionando dados das Universidades interessantes para este projeto.
+├── merge_files_es.py - Script que usa um arquivo de configuração do diretório 'configs' para unir dois CSVs (Cadastro e Remuneração) do portal transparência em um só e salvá-lo no diretório Dados_Servidores/Processados
+└── insert_data.sh - Script que gerencia os outros scripts.
diff --git a/add_registers.sh b/add_registers.sh
new file mode 100755
index 0000000..780b46d
--- /dev/null
+++ b/add_registers.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+./insert_resgiter_payment.sh 2016 11 30
+./insert_resgiter_payment.sh 2016 10 31
+./insert_resgiter_payment.sh 2016 09 30
+./insert_resgiter_payment.sh 2016 08 31
+./insert_resgiter_payment.sh 2016 07 31
+./insert_resgiter_payment.sh 2016 06 30
+./insert_resgiter_payment.sh 2016 05 31
+./insert_resgiter_payment.sh 2016 04 30
+./insert_resgiter_payment.sh 2016 03 31
+./insert_resgiter_payment.sh 2016 02 29
+./insert_resgiter_payment.sh 2016 01 31
+
+./insert_resgiter_payment.sh 2015 12 31
+./insert_resgiter_payment.sh 2015 11 30
+./insert_resgiter_payment.sh 2015 10 31
+./insert_resgiter_payment.sh 2015 09 30
+./insert_resgiter_payment.sh 2015 08 31
+./insert_resgiter_payment.sh 2015 07 31
+./insert_resgiter_payment.sh 2015 06 30
+./insert_resgiter_payment.sh 2015 05 31
+./insert_resgiter_payment.sh 2015 04 30
+./insert_resgiter_payment.sh 2015 03 31
+./insert_resgiter_payment.sh 2015 02 28
+./insert_resgiter_payment.sh 2015 01 31
+
+./insert_resgiter_payment.sh 2014 12 31
+./insert_resgiter_payment.sh 2014 11 30
+./insert_resgiter_payment.sh 2014 10 31
+./insert_resgiter_payment.sh 2014 09 30
+./insert_resgiter_payment.sh 2014 08 31
+./insert_resgiter_payment.sh 2014 07 31
+./insert_resgiter_payment.sh 2014 06 30
+./insert_resgiter_payment.sh 2014 05 31
+./insert_resgiter_payment.sh 2014 04 30
+./insert_resgiter_payment.sh 2014 03 31
+./insert_resgiter_payment.sh 2014 02 28
+./insert_resgiter_payment.sh 2014 01 31
+
+./insert_resgiter_payment.sh 2013 12 31
+./insert_resgiter_payment.sh 2013 11 30
+./insert_resgiter_payment.sh 2013 10 31
+./insert_resgiter_payment.sh 2013 09 30
+./insert_resgiter_payment.sh 2013 08 31
+./insert_resgiter_payment.sh 2013 07 31
+./insert_resgiter_payment.sh 2013 06 30
+./insert_resgiter_payment.sh 2013 05 31
+./insert_resgiter_payment.sh 2013 04 30
+./insert_resgiter_payment.sh 2013 03 31
+./insert_resgiter_payment.sh 2013 02 28
+./insert_resgiter_payment.sh 2013 01 31
diff --git a/configs/config-2016-01.json b/configs/config-2016-01.json
deleted file mode 100644
index 79f65e9..0000000
--- a/configs/config-2016-01.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-01/"
-	, "date": "20160131"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-02.json b/configs/config-2016-02.json
deleted file mode 100644
index f5b11af..0000000
--- a/configs/config-2016-02.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-02/"
-	, "date": "20160229"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-03.json b/configs/config-2016-03.json
deleted file mode 100644
index 08db9b1..0000000
--- a/configs/config-2016-03.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-03/"
-	, "date": "20160331"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-04.json b/configs/config-2016-04.json
deleted file mode 100644
index b1c6c2e..0000000
--- a/configs/config-2016-04.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-04/"
-	, "date": "20160430"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-05.json b/configs/config-2016-05.json
deleted file mode 100644
index 7fd76de..0000000
--- a/configs/config-2016-05.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-05/"
-	, "date": "20160531"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-06.json b/configs/config-2016-06.json
deleted file mode 100644
index 0d8123e..0000000
--- a/configs/config-2016-06.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-06/"
-	, "date": "20160630"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-07.json b/configs/config-2016-07.json
deleted file mode 100644
index eb70d53..0000000
--- a/configs/config-2016-07.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-07/"
-	, "date": "20160731"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-08.json b/configs/config-2016-08.json
deleted file mode 100644
index a3cd033..0000000
--- a/configs/config-2016-08.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-08/"
-	, "date": "20160831"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-09.json b/configs/config-2016-09.json
deleted file mode 100644
index ea230f3..0000000
--- a/configs/config-2016-09.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-09/"
-	, "date": "20160930"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-10.json b/configs/config-2016-10.json
deleted file mode 100644
index c6e61ed..0000000
--- a/configs/config-2016-10.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-10/"
-	, "date": "20161031"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/config-2016-11.json b/configs/config-2016-11.json
deleted file mode 100644
index 9db5dce..0000000
--- a/configs/config-2016-11.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-	"path": "Dados_Servidores/2016-11/"
-	, "date": "20161130"
-    , "file1" : "_Remuneracao.csv"
-    , "file2" : "_Cadastro_Ufpr_Unique.csv"
-    , "idColumn1" : 2
-    , "idColumn2" : 0
-    , "columnsToAdd1" : [2, 4, 5]
-    , "columnsToAdd2" : []
-	, "quotechar": "\""
-    , "delimiter": "\t"
-    , "lineterminator": "\n"
-    , "outputFile": "result.csv"
-    , "notFoundFile1": "not_found_1.txt"
-    , "notFoundFile2": "not_found_2.txt"
-}
diff --git a/configs/generate_config.sh b/configs/generate_config.sh
deleted file mode 100644
index 22810d5..0000000
--- a/configs/generate_config.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-
-read "What is the script's date? [YYYY-MM-DD]:" date
-case $yn in  | YES )
-
-esac
diff --git a/insert_data.sh b/insert_resgiter_payment.sh
similarity index 100%
rename from insert_data.sh
rename to insert_resgiter_payment.sh
diff --git a/logstash_config.example b/logstash_config.example
index bfe3b55..c2d4084 100644
--- a/logstash_config.example
+++ b/logstash_config.example
@@ -8,7 +8,7 @@ input {
 
 filter {
 	csv {
-		columns => [ "ID_SERVIDOR_PORTAL", "NOME", "CPF", "MATRICULA", "DESCRICAO_CARGO", "CLASSE_CARGO", "REFERENCIA_CARGO", "PADRAO_CARGO", "NIVEL_CARGO", "SIGLA_FUNCAO", "NIVEL_FUNCAO", "FUNCAO", "CODIGO_ATIVIDADE", "ATIVIDADE", "OPCAO_PARCIAL", "COD_UORG_LOTACAO", "UORG_LOTACAO", "COD_ORG_LOTACAO", "ORG_LOTACAO", "COD_ORGSUP_LOTACAO", "ORGSUP_LOTACAO", "COD_UORG_EXERCICIO", "UORG_EXERCICIO", "COD_ORG_EXERCICIO", "ORG_EXERCICIO", "COD_ORGSUP_EXERCICIO", "ORGSUP_EXERCICIO", "TIPO_VINCULO", "SITUACAO_VINCULO", "DATA_INICIO_AFASTAMENTO", "DATA_TERMINO_AFASTAMENTO", "REGIME_JURIDICO", "JORNADA_DE_TRABALHO", "DATA_INGRESSO_CARGOFUNCAO", "DATA_NOMEACAO_CARGOFUNCAO", "DATA_INGRESSO_ORGAO", "DOCUMENTO_INGRESSO_SERVICOPUBLICO", "DATA_DIPLOMA_INGRESSO_SERVICOPUBLICO", "DIPLOMA_INGRESSO_CARGOFUNCAO", "DIPLOMA_INGRESSO_ORGAO", "DIPLOMA_INGRESSO_SERVICOPUBLICO", "UF_EXERCICIO", "ANO", "MES", "ID_SERVIDOR_PORTAL", "CPF", "NOME", "REMUNERAÇÃO BÁSICA BRUTA (R$)", "REMUNERAÇÃO BÁSICA BRUTA (U$)", "ABATE-TETO (R$)", "ABATE-TETO (U$)", "GRATIFICAÇÃO NATALINA (R$)", "GRATIFICAÇÃO NATALINA (U$)", "ABATE-TETO DA GRATIFICAÇÃO NATALINA (R$)", "ABATE-TETO DA GRATIFICAÇÃO NATALINA (U$)", "FÉRIAS (R$)", "FÉRIAS (U$)", "OUTRAS REMUNERAÇÕES EVENTUAIS (R$)", "OUTRAS REMUNERAÇÕES EVENTUAIS (U$)", "IRRF (R$)", "IRRF (U$)", "PSS/RPGS (R$)", "PSS/RPGS (U$)", "PENSÃO MILITAR (R$)", "PENSÃO MILITAR (U$)", "FUNDO DE SAÚDE (R$)", "FUNDO DE SAÚDE (U$)", "DEMAIS DEDUÇÕES (R$)", "DEMAIS DEDUÇÕES (U$)", "REMUNERAÇÃO APÓS DEDUÇÕES OBRIGATÓRIAS (R$)", "REMUNERAÇÃO APÓS DEDUÇÕES OBRIGATÓRIAS (U$)", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - CIVIL (R$)(*)", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - CIVIL (U$)(*)    ", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - MILITAR (R$)(*)", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - MILITAR (U$)(*)", "TOTAL DE VERBAS INDENIZATÓRIAS (R$)(*)", "TOTAL DE VERBAS INDENIZATÓRIAS (U$)(*)", "TOTAL DE HONORÁRIOS (JETONS)"]
+		columns => [ "ID_SERVIDOR_PORTAL", "NOME", "CPF", "MATRICULA", "DESCRICAO_CARGO", "CLASSE_CARGO", "REFERENCIA_CARGO", "PADRAO_CARGO", "NIVEL_CARGO", "SIGLA_FUNCAO", "NIVEL_FUNCAO", "FUNCAO", "CODIGO_ATIVIDADE", "ATIVIDADE", "OPCAO_PARCIAL", "COD_UORG_LOTACAO", "UORG_LOTACAO", "COD_ORG_LOTACAO", "ORG_LOTACAO", "COD_ORGSUP_LOTACAO", "ORGSUP_LOTACAO", "COD_UORG_EXERCICIO", "UORG_EXERCICIO", "COD_ORG_EXERCICIO", "ORG_EXERCICIO", "COD_ORGSUP_EXERCICIO", "ORGSUP_EXERCICIO", "TIPO_VINCULO", "SITUACAO_VINCULO", "DATA_INICIO_AFASTAMENTO", "DATA_TERMINO_AFASTAMENTO", "REGIME_JURIDICO", "JORNADA_DE_TRABALHO", "DATA_INGRESSO_CARGOFUNCAO", "DATA_NOMEACAO_CARGOFUNCAO", "DATA_INGRESSO_ORGAO", "DOCUMENTO_INGRESSO_SERVICOPUBLICO", "DATA_DIPLOMA_INGRESSO_SERVICOPUBLICO", "DIPLOMA_INGRESSO_CARGOFUNCAO", "DIPLOMA_INGRESSO_ORGAO", "DIPLOMA_INGRESSO_SERVICOPUBLICO", "UF_EXERCICIO", "ANO", "MES", "REMUNERAÇÃO BÁSICA BRUTA (R$)", "REMUNERAÇÃO BÁSICA BRUTA (U$)", "ABATE-TETO (R$)", "ABATE-TETO (U$)", "GRATIFICAÇÃO NATALINA (R$)", "GRATIFICAÇÃO NATALINA (U$)", "ABATE-TETO DA GRATIFICAÇÃO NATALINA (R$)", "ABATE-TETO DA GRATIFICAÇÃO NATALINA (U$)", "FÉRIAS (R$)", "FÉRIAS (U$)", "OUTRAS REMUNERAÇÕES EVENTUAIS (R$)", "OUTRAS REMUNERAÇÕES EVENTUAIS (U$)", "IRRF (R$)", "IRRF (U$)", "PSS/RPGS (R$)", "PSS/RPGS (U$)", "PENSÃO MILITAR (R$)", "PENSÃO MILITAR (U$)", "FUNDO DE SAÚDE (R$)", "FUNDO DE SAÚDE (U$)", "DEMAIS DEDUÇÕES (R$)", "DEMAIS DEDUÇÕES (U$)", "REMUNERAÇÃO APÓS DEDUÇÕES OBRIGATÓRIAS (R$)", "REMUNERAÇÃO APÓS DEDUÇÕES OBRIGATÓRIAS (U$)", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - CIVIL (R$)(*)", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - CIVIL (U$)(*)    ", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - MILITAR (R$)(*)", "VERBAS INDENIZATÓRIAS REGISTRADAS EM SISTEMAS DE PESSOAL - MILITAR (U$)(*)", "TOTAL DE VERBAS INDENIZATÓRIAS (R$)(*)", "TOTAL DE VERBAS INDENIZATÓRIAS (U$)(*)", "TOTAL DE HONORÁRIOS (JETONS)"]
 		separator => "	"
 		add_field => { "timestamp" => "%(timestamp)s" }
 	}
diff --git a/merge_files_es.py b/merge_files_es.py
index 48517fc..8cb0015 100755
--- a/merge_files_es.py
+++ b/merge_files_es.py
@@ -65,15 +65,20 @@ def getDataFromRows(row1, row2):
     newRow = []
     for value in row2:
         newRow.append(value)
-    for value in row1:
-        newRow.append(value)
+	# Append columns ANO e MES.
+    newRow.append(row1[0])
+    newRow.append(row1[1])
+	# Start i in 5 because we want to ignore columns ID_SERVIDOR_PORTAL, CPF and NOME from Remuneracao.csv (we already have it from Cadastro.csv). We might not have data from them.
+    for i in range(5, len(row1)):
+        newRow.append(row1[i])
     return newRow
 
 def getDataWithEmptyRow(columns, row):
     newRow = []
     for value in row:
         newRow.append(value)
-    for i in range(0, columns):
+	# Append since 3 because we want to ignore columns ID_SERVIDOR_PORTAL, CPF and NOME from Remuneracao.csv (we already have this data from Cadastro.csv).
+    for i in range(3, columns):
         newRow.append('')
     return newRow
 
diff --git a/scripts/expenses/process_expenses.sh b/scripts/expenses/process_expenses.sh
new file mode 100755
index 0000000..1e3ca45
--- /dev/null
+++ b/scripts/expenses/process_expenses.sh
@@ -0,0 +1,76 @@
+./resumo_gastos.sh ../../Favorecidos/ 2016-11
+./resumo_gastos.sh ../../Favorecidos/ 2016-10
+./resumo_gastos.sh ../../Favorecidos/ 2016-09
+./resumo_gastos.sh ../../Favorecidos/ 2016-08
+./resumo_gastos.sh ../../Favorecidos/ 2016-07
+./resumo_gastos.sh ../../Favorecidos/ 2016-06
+./resumo_gastos.sh ../../Favorecidos/ 2016-05
+./resumo_gastos.sh ../../Favorecidos/ 2016-04
+./resumo_gastos.sh ../../Favorecidos/ 2016-03
+./resumo_gastos.sh ../../Favorecidos/ 2016-02
+./resumo_gastos.sh ../../Favorecidos/ 2016-01
+
+./resumo_gastos.sh ../../Favorecidos/ 2015-12
+./resumo_gastos.sh ../../Favorecidos/ 2015-11
+./resumo_gastos.sh ../../Favorecidos/ 2015-10
+./resumo_gastos.sh ../../Favorecidos/ 2015-09
+./resumo_gastos.sh ../../Favorecidos/ 2015-08
+./resumo_gastos.sh ../../Favorecidos/ 2015-07
+./resumo_gastos.sh ../../Favorecidos/ 2015-06
+./resumo_gastos.sh ../../Favorecidos/ 2015-05
+./resumo_gastos.sh ../../Favorecidos/ 2015-04
+./resumo_gastos.sh ../../Favorecidos/ 2015-03
+./resumo_gastos.sh ../../Favorecidos/ 2015-02
+./resumo_gastos.sh ../../Favorecidos/ 2015-01
+
+./resumo_gastos.sh ../../Favorecidos/ 2014-12
+./resumo_gastos.sh ../../Favorecidos/ 2014-11
+./resumo_gastos.sh ../../Favorecidos/ 2014-10
+./resumo_gastos.sh ../../Favorecidos/ 2014-09
+./resumo_gastos.sh ../../Favorecidos/ 2014-08
+./resumo_gastos.sh ../../Favorecidos/ 2014-07
+./resumo_gastos.sh ../../Favorecidos/ 2014-06
+./resumo_gastos.sh ../../Favorecidos/ 2014-05
+./resumo_gastos.sh ../../Favorecidos/ 2014-04
+./resumo_gastos.sh ../../Favorecidos/ 2014-03
+./resumo_gastos.sh ../../Favorecidos/ 2014-02
+./resumo_gastos.sh ../../Favorecidos/ 2014-01
+
+./resumo_gastos.sh ../../Favorecidos/ 2013-12
+./resumo_gastos.sh ../../Favorecidos/ 2013-11
+./resumo_gastos.sh ../../Favorecidos/ 2013-10
+./resumo_gastos.sh ../../Favorecidos/ 2013-09
+./resumo_gastos.sh ../../Favorecidos/ 2013-08
+./resumo_gastos.sh ../../Favorecidos/ 2013-07
+./resumo_gastos.sh ../../Favorecidos/ 2013-06
+./resumo_gastos.sh ../../Favorecidos/ 2013-05
+./resumo_gastos.sh ../../Favorecidos/ 2013-04
+./resumo_gastos.sh ../../Favorecidos/ 2013-03
+./resumo_gastos.sh ../../Favorecidos/ 2013-02
+./resumo_gastos.sh ../../Favorecidos/ 2013-01
+
+./resumo_gastos.sh ../../Favorecidos/ 2012-12
+./resumo_gastos.sh ../../Favorecidos/ 2012-11
+./resumo_gastos.sh ../../Favorecidos/ 2012-10
+./resumo_gastos.sh ../../Favorecidos/ 2012-09
+./resumo_gastos.sh ../../Favorecidos/ 2012-08
+./resumo_gastos.sh ../../Favorecidos/ 2012-07
+./resumo_gastos.sh ../../Favorecidos/ 2012-06
+./resumo_gastos.sh ../../Favorecidos/ 2012-05
+./resumo_gastos.sh ../../Favorecidos/ 2012-04
+./resumo_gastos.sh ../../Favorecidos/ 2012-03
+./resumo_gastos.sh ../../Favorecidos/ 2012-02
+./resumo_gastos.sh ../../Favorecidos/ 2012-01
+
+./resumo_gastos.sh ../../Favorecidos/ 2011-12
+./resumo_gastos.sh ../../Favorecidos/ 2011-11
+./resumo_gastos.sh ../../Favorecidos/ 2011-10
+./resumo_gastos.sh ../../Favorecidos/ 2011-09
+./resumo_gastos.sh ../../Favorecidos/ 2011-08
+./resumo_gastos.sh ../../Favorecidos/ 2011-07
+./resumo_gastos.sh ../../Favorecidos/ 2011-06
+./resumo_gastos.sh ../../Favorecidos/ 2011-05
+./resumo_gastos.sh ../../Favorecidos/ 2011-04
+./resumo_gastos.sh ../../Favorecidos/ 2011-03
+./resumo_gastos.sh ../../Favorecidos/ 2011-02
+./resumo_gastos.sh ../../Favorecidos/ 2011-01
diff --git a/scripts/expenses/resume_expenses.sh b/scripts/expenses/resume_expenses.sh
new file mode 100755
index 0000000..319a7e0
--- /dev/null
+++ b/scripts/expenses/resume_expenses.sh
@@ -0,0 +1,25 @@
+# Setembro 2016
+# Path example: ../../Favorecidos/
+path=$1
+# Date example: 2016-11
+date=$2
+# dateWithoutHyphen example: 201611
+dateWithoutHyphen=${date//-}
+
+if [ "$#" -ne 2 ]; then
+	echo "Usage: $0 <path> <date>"
+	exit
+fi
+
+echo "Processing data with args = $path and ${date}"
+
+input="${path}${date}/${dateWithoutHyphen}_GastosDiretos.csv"
+output="${path}/Processados/${dateWithoutHyphen}.csv"
+
+# About this command:
+# - Grep removes everyone that does not work in UFPR.
+# - Tr removes null characters (ctrl + @).
+# - Head -n1 gets first line (column names). Then, I append the data.
+
+head -n1 $input > $output
+cat $input | egrep --binary-files=text "UNIVERSIDADE FEDERAL DO PARANA" | tr -d '\000' >> $output
diff --git a/scripts/expenses/unzip.sh b/scripts/expenses/unzip.sh
new file mode 100755
index 0000000..922585b
--- /dev/null
+++ b/scripts/expenses/unzip.sh
@@ -0,0 +1,9 @@
+echo Running with args $1 and $2
+
+path="../../Favorecidos/"
+
+mkdir ${path}$1
+mv ~/Downloads/$2_GastosDiretos.zip ${path}$1
+unzip ${path}$1/$2_GastosDiretos.zip
+mv ${path}$2_GastosDiretos.csv ${path}$1
+rm ${path}$1/$2_GastosDiretos.zip
diff --git a/scripts/expenses/unzipCaller.sh b/scripts/expenses/unzipCaller.sh
new file mode 100755
index 0000000..4d49afe
--- /dev/null
+++ b/scripts/expenses/unzipCaller.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+./unzip.sh 2015-12 201512
+./unzip.sh 2015-11 201511
+./unzip.sh 2015-10 201510
+./unzip.sh 2015-09 201509
+./unzip.sh 2015-08 201508
+./unzip.sh 2015-07 201507
+./unzip.sh 2015-06 201506
+./unzip.sh 2015-05 201505
+./unzip.sh 2015-04 201504
+./unzip.sh 2015-03 201503
+./unzip.sh 2015-02 201502
+./unzip.sh 2015-01 201501
+
+./unzip.sh 2014-12 201412
+./unzip.sh 2014-11 201411
+./unzip.sh 2014-10 201410
+./unzip.sh 2014-09 201409
+./unzip.sh 2014-08 201408
+./unzip.sh 2014-07 201407
+./unzip.sh 2014-06 201406
+./unzip.sh 2014-05 201405
+./unzip.sh 2014-04 201404
+./unzip.sh 2014-03 201403
+./unzip.sh 2014-02 201402
+./unzip.sh 2014-01 201401
+
+./unzip.sh 2013-12 201312
+./unzip.sh 2013-11 201311
+./unzip.sh 2013-10 201310
+./unzip.sh 2013-09 201309
+./unzip.sh 2013-08 201308
+./unzip.sh 2013-07 201307
+./unzip.sh 2013-06 201306
+./unzip.sh 2013-05 201305
+./unzip.sh 2013-04 201304
+./unzip.sh 2013-03 201303
+./unzip.sh 2013-02 201302
+./unzip.sh 2013-01 201301
+
+./unzip.sh 2012-12 201212
+./unzip.sh 2012-11 201211
+./unzip.sh 2012-10 201210
+./unzip.sh 2012-09 201209
+./unzip.sh 2012-08 201208
+./unzip.sh 2012-07 201207
+./unzip.sh 2012-06 201206
+./unzip.sh 2012-05 201205
+./unzip.sh 2012-04 201204
+./unzip.sh 2012-03 201203
+./unzip.sh 2012-02 201202
+./unzip.sh 2012-01 201201
+
+./unzip.sh 2011-12 201112
+./unzip.sh 2011-11 201111
+./unzip.sh 2011-10 201110
+./unzip.sh 2011-09 201109
+./unzip.sh 2011-08 201108
+./unzip.sh 2011-07 201107
+./unzip.sh 2011-06 201106
+./unzip.sh 2011-05 201105
+./unzip.sh 2011-04 201104
+./unzip.sh 2011-03 201103
+./unzip.sh 2011-02 201102
+./unzip.sh 2011-01 201101
-- 
GitLab