abank 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -10
- data/lib/abank.rb +13 -11
- data/lib/abank/bigquery.rb +48 -35
- data/lib/abank/folhacalculo.rb +32 -39
- data/lib/abank/version.rb +1 -1
- metadata +2 -3
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4fa823dd3a80abdd91cd205a521b1f00ab236cfd91150a16e1a85ac62af10b3
|
4
|
+
data.tar.gz: a138ebd1ba1cf321429c5d65d219ccaf7549c8489c6ca3d4cf043f026e15a0aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8429fbe87e9fbeb10e64b55e3fd0b42b3e84d9e9305532663ff8991d0716185bce299ce23362fb2de7c35c26584ea37556c3a816945c2fff89367d48cc04b27
|
7
|
+
data.tar.gz: 25279212f35408690c174205720fed6d6a9641ae8cdb78ed4d63eeab2767933dd940b95493d2bbb164a82c1c6719caf405099641566118efaf21e2501cb9f78d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Abank [](https://travis-ci.com/hernanirvaz/abank)
|
2
2
|
|
3
|
-
Arquiva conta-corrente
|
3
|
+
Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery. Permite apagar movimentos similares/existentes ja no bigquery. Permite ainda classificar movimentos ja no bigquery.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -31,15 +31,6 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
|
|
31
31
|
|
32
32
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
33
|
|
34
|
-
## Contributing
|
35
|
-
|
36
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/abank. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/abank/blob/master/CODE_OF_CONDUCT.md).
|
37
|
-
|
38
|
-
|
39
34
|
## License
|
40
35
|
|
41
36
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
42
|
-
|
43
|
-
## Code of Conduct
|
44
|
-
|
45
|
-
Everyone interacting in the Abank project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/abank/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/abank.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'thor'
|
4
|
-
require 'abank/version'
|
5
4
|
require 'abank/bigquery'
|
6
5
|
require 'abank/folhacalculo'
|
6
|
+
require 'abank/version'
|
7
7
|
|
8
|
+
# @author Hernani Rodrigues Vaz
|
8
9
|
module Abank
|
9
10
|
ID = `whoami`.chomp
|
10
11
|
|
@@ -18,15 +19,16 @@ module Abank
|
|
18
19
|
option :x, banner: 'EXT', default: '.xlsx',
|
19
20
|
desc: 'Extensao das folhas calculo'
|
20
21
|
option :s, type: :boolean, default: false,
|
21
|
-
desc: 'apaga
|
22
|
+
desc: 'apaga linha similar no bigquery'
|
22
23
|
option :e, type: :boolean, default: false,
|
23
|
-
desc: 'apaga
|
24
|
-
|
24
|
+
desc: 'apaga linha igual no bigquery'
|
25
|
+
option :m, type: :boolean, default: false,
|
26
|
+
desc: 'apaga linhas existencia multipla no bigquery'
|
27
|
+
# processa folha calculo
|
25
28
|
def load
|
26
|
-
# opcoes apagar linhas
|
27
|
-
d = options.select { |_, v| [true, false].include?(v) }
|
28
29
|
Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
|
29
|
-
Bigquery.new(f,
|
30
|
+
Bigquery.new(f, { s: options[:s], e: options[:e],
|
31
|
+
m: options[:m], i: true }).processa
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -35,17 +37,17 @@ module Abank
|
|
35
37
|
desc: 'Onde procurar folhas calculo'
|
36
38
|
option :x, banner: 'EXT', default: '.xlsx',
|
37
39
|
desc: 'Extensao das folhas calculo'
|
38
|
-
# mostra
|
40
|
+
# mostra folha calculo
|
39
41
|
def mostra
|
40
42
|
Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
|
41
|
-
Bigquery.new(f).
|
43
|
+
Bigquery.new(f).processa
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
desc 'classifica', 'classifica arquivo no bigquery'
|
46
|
-
# classifica bigquery
|
48
|
+
# classifica arquivo no bigquery
|
47
49
|
def classifica
|
48
|
-
Bigquery.new.
|
50
|
+
Bigquery.new.classifica
|
49
51
|
end
|
50
52
|
|
51
53
|
default_task :mostra
|
data/lib/abank/bigquery.rb
CHANGED
@@ -6,45 +6,47 @@ require 'google/cloud/bigquery'
|
|
6
6
|
module Abank
|
7
7
|
DF = '%Y-%m-%d'
|
8
8
|
|
9
|
-
#
|
9
|
+
# (see Bigquery)
|
10
10
|
class Bigquery
|
11
|
+
# @return [Google::Cloud::Bigquery] API bigquery
|
12
|
+
attr_reader :apibq
|
11
13
|
# @return [Roo::Excelx] folha calculo a processar
|
12
|
-
attr_reader :
|
14
|
+
attr_reader :folha
|
15
|
+
# @return [Hash<Symbol, Boolean>] opcoes trabalho com linhas
|
16
|
+
attr_reader :linha
|
17
|
+
# @return [Integer] numero conta
|
18
|
+
attr_reader :conta
|
19
|
+
|
13
20
|
# @return [Array] row folha calculo em processamento
|
14
21
|
attr_reader :row
|
15
|
-
# @return [Google::Cloud::Bigquery] API bigquery
|
16
|
-
attr_reader :api
|
17
22
|
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
18
23
|
attr_reader :job
|
19
24
|
# @return (see sql_select)
|
20
25
|
attr_reader :sql
|
21
|
-
# @return [Integer] numero conta
|
22
|
-
attr_reader :num
|
23
|
-
# @return [Hash<String, Boolean>] opcoes apagar linhas
|
24
|
-
attr_reader :apaga
|
25
26
|
|
26
|
-
# permite processa folhas calculo comuns no bigquery
|
27
|
-
#
|
28
27
|
# @param [String] xls folha calculo para processar
|
29
|
-
# @param [Hash<
|
30
|
-
# @option
|
31
|
-
# @option
|
32
|
-
# @
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
# @param [Hash<Symbol, Boolean>] ops opcoes trabalho com linhas
|
29
|
+
# @option ops [Boolean] :s (false) apaga linha similar?
|
30
|
+
# @option ops [Boolean] :e (false) apaga linha igual?
|
31
|
+
# @option ops [Boolean] :m (false) apaga linhas existencia multipla?
|
32
|
+
# @option ops [Boolean] :i (false) insere linha nova?
|
33
|
+
# @return [Bigquery] acesso folhas calculo activobank
|
34
|
+
# & correspondente bigquery dataset
|
35
|
+
def initialize(xls = '', ops = { s: false, e: false, m: false, i: false })
|
37
36
|
# usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
|
38
37
|
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
39
|
-
@
|
38
|
+
@apibq = Google::Cloud::Bigquery.new
|
39
|
+
@folha = Roo::Spreadsheet.open(xls) if xls.size.positive?
|
40
|
+
@linha = ops
|
41
|
+
@conta = xls.match?(/card/i) ? 2 : 1
|
40
42
|
end
|
41
43
|
|
42
44
|
# cria job bigquery & verifica execucao
|
43
45
|
#
|
44
|
-
# @param [String] sql
|
46
|
+
# @param [String] sql a executar
|
45
47
|
# @return [Boolean] job ok?
|
46
48
|
def job_bigquery?(sql)
|
47
|
-
@job =
|
49
|
+
@job = apibq.query_job(sql)
|
48
50
|
@job.wait_until_done!
|
49
51
|
puts @job.error['message'] if @job.failed?
|
50
52
|
@job.failed?
|
@@ -58,39 +60,50 @@ module Abank
|
|
58
60
|
job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
|
59
61
|
end
|
60
62
|
|
61
|
-
#
|
63
|
+
# pesquisa existencia linha folha calculo no bigquery
|
62
64
|
#
|
63
|
-
# @return [
|
65
|
+
# @return [Google::Cloud::Bigquery::Data] resultado do sql num array<hash>
|
64
66
|
def sql_select
|
65
|
-
#
|
67
|
+
# array.count = 0 ==> pode carregar esta linha
|
68
|
+
# array.count = 1 ==> mais testes necessarios
|
69
|
+
# array.count > 1 ==> nao carregar esta linha
|
66
70
|
@sql = job_bigquery?('select * ' + sql_where) ? [{}, {}] : job.data
|
67
71
|
end
|
68
72
|
|
69
73
|
# @return [String] parte sql para processamento linhas similares
|
70
74
|
def sql_where
|
71
|
-
"from ab.mv where nc=#{
|
75
|
+
"from hernanilr.ab.mv where nc=#{conta}" \
|
72
76
|
" and dl='#{row[0].strftime(DF)}'" \
|
73
77
|
" and vl=#{row[3]}"
|
74
78
|
end
|
75
79
|
|
76
|
-
# classifica
|
77
|
-
def
|
80
|
+
# (see CLI#classifica)
|
81
|
+
def classifica
|
82
|
+
return unless linha[:i]
|
83
|
+
|
78
84
|
puts 'LINHAS CLASSIFICADAS ' +
|
79
|
-
dml('update ab.mv set mv.ct=tt.nct' \
|
80
|
-
'
|
81
|
-
'where mv.dl=tt.dl and mv.dv=tt.dv' \
|
82
|
-
'
|
85
|
+
dml('update hernanilr.ab.mv set mv.ct=tt.nct' \
|
86
|
+
' from (select * from hernanilr.ab.cl) as tt' \
|
87
|
+
' where mv.dl=tt.dl and mv.dv=tt.dv' \
|
88
|
+
' and mv.ds=tt.ds and mv.vl=tt.vl').to_s
|
83
89
|
end
|
84
90
|
|
85
91
|
# @return [Integer] numero linhas inseridas
|
86
92
|
def sql_insert
|
87
|
-
|
88
|
-
|
89
|
-
|
93
|
+
return 1 unless linha[:i]
|
94
|
+
|
95
|
+
dml('insert hernanilr.ab.mv(dl,dv,ds,vl,nc,ano,mes,ct,tp) VALUES(' \
|
96
|
+
"'#{row[0].strftime(DF)}','#{row[1].strftime(DF)}','#{row[2]}'" +
|
97
|
+
str_insert1)
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [String] campos extra da linha bigquery
|
101
|
+
def str_insert1
|
102
|
+
",#{row[3]},#{conta}" + str_insert2
|
90
103
|
end
|
91
104
|
|
92
105
|
# @return [String] campos calculados da linha bigquery
|
93
|
-
def
|
106
|
+
def str_insert2
|
94
107
|
",#{row[1].year},#{row[1].month},null,'#{row[3].positive? ? 'c' : 'd'}')"
|
95
108
|
end
|
96
109
|
|
data/lib/abank/folhacalculo.rb
CHANGED
@@ -4,60 +4,41 @@ module Abank
|
|
4
4
|
HT = ['Data Lanc.', 'Data Valor', 'Descrição', 'Valor'].freeze
|
5
5
|
RF = '%<v3>-50.50s %<v4>8.2f'
|
6
6
|
|
7
|
-
# folhas calculo
|
7
|
+
# classifica & arquiva dados das folhas calculo activobank no bigquery
|
8
8
|
class Bigquery
|
9
|
-
#
|
9
|
+
# corrige linha folha calculo para processamento
|
10
10
|
#
|
11
11
|
# @param [Hash] has da linha em processamento
|
12
12
|
def corrige_hash(has)
|
13
13
|
@row = has.values
|
14
14
|
@row[2] = row[2].strip
|
15
|
-
@row[3] = -1 * row[3] if
|
15
|
+
@row[3] = -1 * row[3] if conta > 1
|
16
16
|
end
|
17
17
|
|
18
|
-
# processa linhas folha calculo
|
18
|
+
# processa linhas folha calculo & classifica bigquery
|
19
19
|
def processa
|
20
20
|
n = 0
|
21
|
-
|
22
|
-
book.sheet(0).parse(header_search: HT) do |r|
|
21
|
+
folha.sheet(0).parse(header_search: HT) do |r|
|
23
22
|
n += 1
|
24
|
-
puts n == 1 ? "\n" +
|
25
|
-
end
|
26
|
-
sql_update
|
27
|
-
end
|
28
|
-
|
29
|
-
# mostra linhas folha calculo
|
30
|
-
def show
|
31
|
-
n = 0
|
32
|
-
# usada somente a primeira sheet
|
33
|
-
book.sheet(0).parse(header_search: HT) do |r|
|
34
|
-
n += 1
|
35
|
-
puts n == 1 ? "\n" + book.info : show_row(r)
|
23
|
+
puts n == 1 ? "\n" + folha.info : processa_row(r)
|
36
24
|
end
|
25
|
+
classifica
|
37
26
|
end
|
38
27
|
|
39
28
|
# processa linha folha calculo para arquivo
|
40
29
|
#
|
41
30
|
# @param (see corrige_hash)
|
42
|
-
# @return [String]
|
31
|
+
# @return [String] texto informativo do processamento
|
43
32
|
def processa_row(has)
|
44
33
|
corrige_hash(has)
|
45
34
|
sql_select
|
46
|
-
if
|
47
|
-
elsif
|
48
|
-
elsif
|
35
|
+
if row_naoexiste? then row_str + (sql_insert == 1 ? ' NOVA' : ' ERRO')
|
36
|
+
elsif row_simila? then row_similar
|
37
|
+
elsif row_existe? then row_existente
|
38
|
+
else row_multiplas
|
49
39
|
end
|
50
40
|
end
|
51
41
|
|
52
|
-
# obtem linha folha calculo para apresentacao
|
53
|
-
#
|
54
|
-
# @param (see corrige_hash)
|
55
|
-
# @return (see row_str)
|
56
|
-
def show_row(has)
|
57
|
-
corrige_hash(has)
|
58
|
-
row_str
|
59
|
-
end
|
60
|
-
|
61
42
|
# @return [String] linha folha calculo formatada
|
62
43
|
def row_str
|
63
44
|
"#{row[0].strftime(DF)} #{row[1].strftime(DF)} " \
|
@@ -66,28 +47,40 @@ module Abank
|
|
66
47
|
|
67
48
|
# @return [String] linha folha calculo similar
|
68
49
|
def row_similar
|
69
|
-
d =
|
70
|
-
row_str +
|
50
|
+
d = linha[:s] ? sql_delete : 0
|
51
|
+
row_str + ' SIMILAR' + str_apagadas(d) + sql.first[:ds].strip
|
71
52
|
end
|
72
53
|
|
73
54
|
# @return [String] linha folha calculo existente
|
74
55
|
def row_existente
|
75
|
-
d =
|
76
|
-
row_str +
|
56
|
+
d = linha[:e] ? sql_delete : 0
|
57
|
+
row_str + ' EXISTENTE' + str_apagadas(d)
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String] linha folha calculo existencia multipla
|
61
|
+
def row_multiplas
|
62
|
+
d = linha[:m] ? sql_delete : 0
|
63
|
+
row_str + ' MULTIPLAS ' + sql.count.to_s + str_apagadas(d)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [Integer] numero linhas apagadas
|
67
|
+
# @return [String] texto formatado linhas apagadas
|
68
|
+
def str_apagadas(num)
|
69
|
+
num.positive? ? ' & ' + num.to_s + ' APAGADA(S) ' : ' '
|
77
70
|
end
|
78
71
|
|
79
72
|
# @return [Boolean] linha folha calculo nao existe no bigquery?
|
80
|
-
def
|
73
|
+
def row_naoexiste?
|
81
74
|
sql.count.zero?
|
82
75
|
end
|
83
76
|
|
84
77
|
# @return [Boolean] linha folha calculo existe no bigquery?
|
85
|
-
def
|
78
|
+
def row_existe?
|
86
79
|
sql.count == 1 && sql.first[:ds].strip == row[2]
|
87
80
|
end
|
88
81
|
|
89
|
-
# @return [Boolean] linha folha calculo parecida no bigquery?
|
90
|
-
def
|
82
|
+
# @return [Boolean] linha folha calculo existe parecida no bigquery?
|
83
|
+
def row_simila?
|
91
84
|
sql.count == 1 && sql.first[:ds].strip != row[2]
|
92
85
|
end
|
93
86
|
end
|
data/lib/abank/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,7 +106,6 @@ extra_rdoc_files: []
|
|
106
106
|
files:
|
107
107
|
- ".gitignore"
|
108
108
|
- ".travis.yml"
|
109
|
-
- CODE_OF_CONDUCT.md
|
110
109
|
- Gemfile
|
111
110
|
- Gemfile.lock
|
112
111
|
- LICENSE.txt
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at hernanirvaz@gmail.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: https://contributor-covenant.org
|
74
|
-
[version]: https://contributor-covenant.org/version/1/4/
|