eost 0.1.3
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 +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +86 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/eost.gemspec +39 -0
- data/exe/eost +6 -0
- data/lib/eost.rb +47 -0
- data/lib/eost/bigquery.rb +102 -0
- data/lib/eost/folhacalculo.rb +95 -0
- data/lib/eost/version.rb +5 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 26150cc1f7bb4bab759957e79dd517d22c4fa78b970bf1644e9ab2640d68b049
|
|
4
|
+
data.tar.gz: 87c983e443cc415679b3ecbce48f1f4df7f2fbe2a0b32293e9090942c7f24fcb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4a84238e1a425df8e86c651dd3bec214cb7c522b22efb1d7cae236ad44d684e8b68c5c06b21b6ae7103a3406c1acf475b60a3612ef2b08056ab831b289f1c906
|
|
7
|
+
data.tar.gz: c4752ba045f65fee93b6af7ae268ab6c06f20f0b41efcb65b05e110f31f79f3f6ef602cc18d7c0aa6eddc3320435737178c76325eb50d23815cfd3e7d679217d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
eost (0.1.3)
|
|
5
|
+
google-cloud-bigquery
|
|
6
|
+
roo
|
|
7
|
+
thor
|
|
8
|
+
yard
|
|
9
|
+
|
|
10
|
+
GEM
|
|
11
|
+
remote: https://rubygems.org/
|
|
12
|
+
specs:
|
|
13
|
+
addressable (2.7.0)
|
|
14
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
15
|
+
concurrent-ruby (1.1.6)
|
|
16
|
+
declarative (0.0.10)
|
|
17
|
+
declarative-option (0.1.0)
|
|
18
|
+
faraday (1.0.1)
|
|
19
|
+
multipart-post (>= 1.2, < 3)
|
|
20
|
+
google-api-client (0.38.0)
|
|
21
|
+
addressable (~> 2.5, >= 2.5.1)
|
|
22
|
+
googleauth (~> 0.9)
|
|
23
|
+
httpclient (>= 2.8.1, < 3.0)
|
|
24
|
+
mini_mime (~> 1.0)
|
|
25
|
+
representable (~> 3.0)
|
|
26
|
+
retriable (>= 2.0, < 4.0)
|
|
27
|
+
signet (~> 0.12)
|
|
28
|
+
google-cloud-bigquery (1.21.0)
|
|
29
|
+
concurrent-ruby (~> 1.0)
|
|
30
|
+
google-api-client (~> 0.33)
|
|
31
|
+
google-cloud-core (~> 1.2)
|
|
32
|
+
googleauth (~> 0.9)
|
|
33
|
+
mini_mime (~> 1.0)
|
|
34
|
+
google-cloud-core (1.5.0)
|
|
35
|
+
google-cloud-env (~> 1.0)
|
|
36
|
+
google-cloud-errors (~> 1.0)
|
|
37
|
+
google-cloud-env (1.3.1)
|
|
38
|
+
faraday (>= 0.17.3, < 2.0)
|
|
39
|
+
google-cloud-errors (1.0.0)
|
|
40
|
+
googleauth (0.12.0)
|
|
41
|
+
faraday (>= 0.17.3, < 2.0)
|
|
42
|
+
jwt (>= 1.4, < 3.0)
|
|
43
|
+
memoist (~> 0.16)
|
|
44
|
+
multi_json (~> 1.11)
|
|
45
|
+
os (>= 0.9, < 2.0)
|
|
46
|
+
signet (~> 0.14)
|
|
47
|
+
httpclient (2.8.3)
|
|
48
|
+
jwt (2.2.1)
|
|
49
|
+
memoist (0.16.2)
|
|
50
|
+
mini_mime (1.0.2)
|
|
51
|
+
mini_portile2 (2.4.0)
|
|
52
|
+
multi_json (1.14.1)
|
|
53
|
+
multipart-post (2.1.1)
|
|
54
|
+
nokogiri (1.10.9)
|
|
55
|
+
mini_portile2 (~> 2.4.0)
|
|
56
|
+
os (1.1.0)
|
|
57
|
+
public_suffix (4.0.4)
|
|
58
|
+
rake (12.3.3)
|
|
59
|
+
representable (3.0.4)
|
|
60
|
+
declarative (< 0.1.0)
|
|
61
|
+
declarative-option (< 0.2.0)
|
|
62
|
+
uber (< 0.2.0)
|
|
63
|
+
retriable (3.1.2)
|
|
64
|
+
roo (2.8.3)
|
|
65
|
+
nokogiri (~> 1)
|
|
66
|
+
rubyzip (>= 1.3.0, < 3.0.0)
|
|
67
|
+
rubyzip (2.3.0)
|
|
68
|
+
signet (0.14.0)
|
|
69
|
+
addressable (~> 2.3)
|
|
70
|
+
faraday (>= 0.17.3, < 2.0)
|
|
71
|
+
jwt (>= 1.5, < 3.0)
|
|
72
|
+
multi_json (~> 1.10)
|
|
73
|
+
thor (1.0.1)
|
|
74
|
+
uber (0.1.0)
|
|
75
|
+
yard (0.9.24)
|
|
76
|
+
|
|
77
|
+
PLATFORMS
|
|
78
|
+
ruby
|
|
79
|
+
|
|
80
|
+
DEPENDENCIES
|
|
81
|
+
bundler
|
|
82
|
+
eost!
|
|
83
|
+
rake (~> 12.0)
|
|
84
|
+
|
|
85
|
+
BUNDLED WITH
|
|
86
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Hernâni Rodrigues Vaz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Eost [](https://travis-ci.com/hernanirvaz/eost)
|
|
2
|
+
|
|
3
|
+
Arquiva eos-transactions.csv no bigquery. Pode apagar movimentos existentes ja no bigquery.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'eost'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install eost
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
$ eost help [COMANDO] # ajuda aos comandos
|
|
24
|
+
$ eost mostra # mostra dados da folha calculo
|
|
25
|
+
$ eost load # carrega dados da folha calculo no bigquery
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
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).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eost. 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]/eost/blob/master/CODE_OF_CONDUCT.md).
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
41
|
+
|
|
42
|
+
## Code of Conduct
|
|
43
|
+
|
|
44
|
+
Everyone interacting in the Eost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/eost/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "eost"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/eost.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/eost/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'eost'
|
|
7
|
+
spec.version = Eost::VERSION
|
|
8
|
+
spec.authors = ['Hernâni Rodrigues Vaz']
|
|
9
|
+
spec.email = ['hernanirvaz@gmail.com']
|
|
10
|
+
spec.homepage = 'https://github.com/hernanirvaz/abank'
|
|
11
|
+
spec.license = 'MIT'
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Arquiva eos-transactions.csv no bigquery.'
|
|
14
|
+
spec.description = spec.summary +
|
|
15
|
+
' Pode apagar movimentos existentes ja no bigquery.'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['yard.run'] = 'yard'
|
|
19
|
+
|
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads files in RubyGem that have been added into git.
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
25
|
+
`git ls-files -z`.split("\x0")
|
|
26
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = 'exe'
|
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
|
|
32
|
+
spec.add_development_dependency 'bundler'
|
|
33
|
+
spec.add_development_dependency 'rake'
|
|
34
|
+
|
|
35
|
+
spec.add_dependency 'google-cloud-bigquery'
|
|
36
|
+
spec.add_dependency 'roo'
|
|
37
|
+
spec.add_dependency 'thor'
|
|
38
|
+
spec.add_dependency 'yard'
|
|
39
|
+
end
|
data/exe/eost
ADDED
data/lib/eost.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'eost/version'
|
|
5
|
+
require 'eost/bigquery'
|
|
6
|
+
require 'eost/folhacalculo'
|
|
7
|
+
|
|
8
|
+
module Eost
|
|
9
|
+
ID = `whoami`.chomp
|
|
10
|
+
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
|
|
13
|
+
# CLI para carregar folhas calculo comuns no bigquery
|
|
14
|
+
class CLI < Thor
|
|
15
|
+
desc 'load', 'carrega dados da folha calculo no bigquery'
|
|
16
|
+
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
|
|
17
|
+
desc: 'Onde procurar folhas calculo'
|
|
18
|
+
option :x, banner: 'EXT', default: '.csv',
|
|
19
|
+
desc: 'Extensao das folhas calculo'
|
|
20
|
+
option :s, type: :boolean, default: false,
|
|
21
|
+
desc: 'apaga linhas similares no bigquery'
|
|
22
|
+
option :e, type: :boolean, default: false,
|
|
23
|
+
desc: 'apaga linhas existentes no bigquery'
|
|
24
|
+
# processa xlsx
|
|
25
|
+
def load
|
|
26
|
+
# opcoes apagar linhas
|
|
27
|
+
d = options.select { |_, v| [true, false].include?(v) }
|
|
28
|
+
Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
|
|
29
|
+
Bigquery.new(f, d).processa
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc 'mostra', 'mostra dados da folha calculo'
|
|
34
|
+
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
|
|
35
|
+
desc: 'Onde procurar folhas calculo'
|
|
36
|
+
option :x, banner: 'EXT', default: '.csv',
|
|
37
|
+
desc: 'Extensao das folhas calculo'
|
|
38
|
+
# mostra xlsx
|
|
39
|
+
def mostra
|
|
40
|
+
Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
|
|
41
|
+
Bigquery.new(f).show
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
default_task :mostra
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'roo'
|
|
4
|
+
require 'google/cloud/bigquery'
|
|
5
|
+
|
|
6
|
+
module Eost
|
|
7
|
+
DF = '%Y-%m-%d'
|
|
8
|
+
|
|
9
|
+
# folhas calculo comuns no bigquery
|
|
10
|
+
class Bigquery
|
|
11
|
+
# @return [Roo::Excelx] folha calculo a processar
|
|
12
|
+
attr_reader :book
|
|
13
|
+
# @return [Array] row folha calculo em processamento
|
|
14
|
+
attr_reader :row
|
|
15
|
+
# @return [Google::Cloud::Bigquery] API bigquery
|
|
16
|
+
attr_reader :api
|
|
17
|
+
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
|
18
|
+
attr_reader :job
|
|
19
|
+
# @return (see sql_select)
|
|
20
|
+
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
|
+
# permite processa folhas calculo comuns no bigquery
|
|
27
|
+
#
|
|
28
|
+
# @param [String] csv folha calculo para processar
|
|
29
|
+
# @param [Hash<String, Boolean>] apaga opcoes apagar linhas
|
|
30
|
+
# @option apaga [Boolean] s apaga linhas similares sim/nao?
|
|
31
|
+
# @option apaga [Boolean] e apaga linhas existentes sim/nao?
|
|
32
|
+
# @return [Bigquery] acesso folha calculo & bigquery
|
|
33
|
+
def initialize(csv = '', apaga = {})
|
|
34
|
+
@book = Roo::CSV.new(csv) if csv.size.positive?
|
|
35
|
+
@num = csv.match?(/card/i) ? 2 : 1
|
|
36
|
+
@apaga = apaga
|
|
37
|
+
# usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
|
|
38
|
+
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
|
39
|
+
@api = Google::Cloud::Bigquery.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# cria job bigquery & verifica execucao
|
|
43
|
+
#
|
|
44
|
+
# @param [String] sql para executar
|
|
45
|
+
# @return [Boolean] job ok?
|
|
46
|
+
def job_bigquery?(sql)
|
|
47
|
+
@job = api.query_job(sql)
|
|
48
|
+
@job.wait_until_done!
|
|
49
|
+
puts @job.error['message'] if @job.failed?
|
|
50
|
+
@job.failed?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# cria Data Manipulation Language (DML) job bigquery
|
|
54
|
+
#
|
|
55
|
+
# @param (see job_bigquery?)
|
|
56
|
+
# @return [Integer] numero linhas afetadas
|
|
57
|
+
def dml(sql)
|
|
58
|
+
job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# cria sql job bigquery com resultados
|
|
62
|
+
#
|
|
63
|
+
# @return [Array<Hash>] resultado sql
|
|
64
|
+
def sql_select
|
|
65
|
+
# se array.count > 1 => nao fazer nada
|
|
66
|
+
@sql = job_bigquery?('select * ' + sql_where) ? [{}, {}] : job.data
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @return [String] parte sql para processamento linhas similares
|
|
70
|
+
def sql_where
|
|
71
|
+
"from ab.mv where nc=#{num}" \
|
|
72
|
+
" and dl='#{row[0].strftime(DF)}'" \
|
|
73
|
+
" and vl=#{row[3]}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# classifica linhas
|
|
77
|
+
def sql_update
|
|
78
|
+
puts 'LINHAS CLASSIFICADAS ' +
|
|
79
|
+
dml('update ab.mv set mv.ct=tt.nct' \
|
|
80
|
+
' from (select * from ab.cl) as tt ' \
|
|
81
|
+
'where mv.dl=tt.dl and mv.dv=tt.dv' \
|
|
82
|
+
' and mv.ds=tt.ds and mv.vl=tt.vl').to_s
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @return [Integer] numero linhas inseridas
|
|
86
|
+
def sql_insert
|
|
87
|
+
dml('insert ab.mv(dl,dv,ds,vl,nc,ano,mes,ct,tp) VALUES(' \
|
|
88
|
+
"'#{row[0].strftime(DF)}','#{row[1].strftime(DF)}','#{row[2]}'," \
|
|
89
|
+
"#{row[3]},#{num}" + sql_insert_calculado)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# @return [String] campos calculados da linha bigquery
|
|
93
|
+
def sql_insert_calculado
|
|
94
|
+
",#{row[1].year},#{row[1].month},null,'#{row[3].positive? ? 'c' : 'd'}')"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# @return [Integer] numero linhas apagadas
|
|
98
|
+
def sql_delete
|
|
99
|
+
dml('delete ' + sql_where + " and ds='#{sql.first[:ds].strip}'")
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Eost
|
|
4
|
+
HT = %w[block_num block_time contract action \
|
|
5
|
+
from to amount symbol memo data].freeze
|
|
6
|
+
RF = '%<v3>-50.50s %<v4>8.2f'
|
|
7
|
+
|
|
8
|
+
# folhas calculo comuns no bigquery
|
|
9
|
+
class Bigquery
|
|
10
|
+
# prepara linha folha calculo para processamento
|
|
11
|
+
#
|
|
12
|
+
# @param [Hash] has da linha em processamento
|
|
13
|
+
def corrige_hash(has)
|
|
14
|
+
@row = has.values
|
|
15
|
+
@row[2] = row[2].strip
|
|
16
|
+
@row[3] = -1 * row[3] if num > 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# processa linhas folha calculo
|
|
20
|
+
def processa
|
|
21
|
+
n = 0
|
|
22
|
+
# usada somente a primeira sheet
|
|
23
|
+
book.sheet(0).parse(header_search: HT) do |r|
|
|
24
|
+
n += 1
|
|
25
|
+
puts n == 1 ? "\n" + book.info : processa_row(r)
|
|
26
|
+
end
|
|
27
|
+
sql_update
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# mostra linhas folha calculo
|
|
31
|
+
def show
|
|
32
|
+
n = 0
|
|
33
|
+
# usada somente a primeira sheet
|
|
34
|
+
book.sheet(0).parse(header_search: HT) do |r|
|
|
35
|
+
n += 1
|
|
36
|
+
puts n == 1 ? "\n" + book.info : show_row(r)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# processa linha folha calculo para arquivo
|
|
41
|
+
#
|
|
42
|
+
# @param (see corrige_hash)
|
|
43
|
+
# @return [String] linha folha calculo processada
|
|
44
|
+
def processa_row(has)
|
|
45
|
+
corrige_hash(has)
|
|
46
|
+
sql_select
|
|
47
|
+
if rnaoexiste? then row_str + (sql_insert == 1 ? ' NOVA' : ' ERRO')
|
|
48
|
+
elsif rsimila? then row_similar
|
|
49
|
+
elsif rexiste? then row_existente
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# obtem linha folha calculo para apresentacao
|
|
54
|
+
#
|
|
55
|
+
# @param (see corrige_hash)
|
|
56
|
+
# @return (see row_str)
|
|
57
|
+
def show_row(has)
|
|
58
|
+
corrige_hash(has)
|
|
59
|
+
row_str
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @return [String] linha folha calculo formatada
|
|
63
|
+
def row_str
|
|
64
|
+
"#{row[0].strftime(DF)} #{row[1].strftime(DF)} " \
|
|
65
|
+
"#{format(RF, v3: row[2], v4: row[3])}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @return [String] linha folha calculo similar
|
|
69
|
+
def row_similar
|
|
70
|
+
d = apaga['s'] ? sql_delete : 0
|
|
71
|
+
row_str + " SIMILAR#{d.zero? ? ' ' : ' APAGADA '}#{sql.first[:ds].strip}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# @return [String] linha folha calculo existente
|
|
75
|
+
def row_existente
|
|
76
|
+
d = apaga['e'] ? sql_delete : 0
|
|
77
|
+
row_str + " EXISTENTE#{d.zero? ? '' : ' APAGADA'}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# @return [Boolean] linha folha calculo nao existe no bigquery?
|
|
81
|
+
def rnaoexiste?
|
|
82
|
+
sql.count.zero?
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @return [Boolean] linha folha calculo existe no bigquery?
|
|
86
|
+
def rexiste?
|
|
87
|
+
sql.count == 1 && sql.first[:ds].strip == row[2]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @return [Boolean] linha folha calculo parecida no bigquery?
|
|
91
|
+
def rsimila?
|
|
92
|
+
sql.count == 1 && sql.first[:ds].strip != row[2]
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
data/lib/eost/version.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: eost
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Hernâni Rodrigues Vaz
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: google-cloud-bigquery
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: roo
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: thor
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: yard
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: Arquiva eos-transactions.csv no bigquery. Pode apagar movimentos existentes
|
|
98
|
+
ja no bigquery.
|
|
99
|
+
email:
|
|
100
|
+
- hernanirvaz@gmail.com
|
|
101
|
+
executables:
|
|
102
|
+
- eost
|
|
103
|
+
extensions: []
|
|
104
|
+
extra_rdoc_files: []
|
|
105
|
+
files:
|
|
106
|
+
- ".gitignore"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- CODE_OF_CONDUCT.md
|
|
109
|
+
- Gemfile
|
|
110
|
+
- Gemfile.lock
|
|
111
|
+
- LICENSE.txt
|
|
112
|
+
- README.md
|
|
113
|
+
- Rakefile
|
|
114
|
+
- bin/console
|
|
115
|
+
- bin/setup
|
|
116
|
+
- eost.gemspec
|
|
117
|
+
- exe/eost
|
|
118
|
+
- lib/eost.rb
|
|
119
|
+
- lib/eost/bigquery.rb
|
|
120
|
+
- lib/eost/folhacalculo.rb
|
|
121
|
+
- lib/eost/version.rb
|
|
122
|
+
homepage: https://github.com/hernanirvaz/abank
|
|
123
|
+
licenses:
|
|
124
|
+
- MIT
|
|
125
|
+
metadata:
|
|
126
|
+
homepage_uri: https://github.com/hernanirvaz/abank
|
|
127
|
+
yard.run: yard
|
|
128
|
+
post_install_message:
|
|
129
|
+
rdoc_options: []
|
|
130
|
+
require_paths:
|
|
131
|
+
- lib
|
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: 2.3.0
|
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '0'
|
|
142
|
+
requirements: []
|
|
143
|
+
rubygems_version: 3.0.3
|
|
144
|
+
signing_key:
|
|
145
|
+
specification_version: 4
|
|
146
|
+
summary: Arquiva eos-transactions.csv no bigquery.
|
|
147
|
+
test_files: []
|