arquivo 0.2.4 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +32 -15
- data/README.md +1 -1
- data/arquivo.gemspec +3 -1
- data/lib/arquivo.rb +8 -0
- data/lib/arquivo/bigquery.rb +53 -0
- data/lib/arquivo/dir.rb +7 -40
- data/lib/arquivo/sheets.rb +46 -0
- data/lib/arquivo/version.rb +1 -1
- metadata +37 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d030623f8fd4780d6207d8ad206a06f9b7eb35e1cf2e484d10697bfe5ec1aa4
|
4
|
+
data.tar.gz: 5b3c49c43d6b607290db7e0582e0b84a7a87b1d5c6bece2cf2b697bab60e9ce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6046db2f720435c3548a9df7cf96d2846d572c3fd5ca259cd3dcbc233d99e7c97414594390d211426b60eea268e3d20d09acb1aa69359c4be7f4990387b26a
|
7
|
+
data.tar.gz: 89c01519dcedbfa9cda6b4fe05887156ab93a31358e15eccde40796531655f4ecb6d23fd7b6127d7203bf52620e25c7a96631d6c50415d3def7ad0522804b1a1
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arquivo (0.2.
|
4
|
+
arquivo (0.2.9)
|
5
5
|
fastimage (~> 2.1)
|
6
6
|
google-api-client (~> 0.34)
|
7
|
+
google-cloud-bigquery
|
8
|
+
i18n
|
7
9
|
pdf-reader (~> 2.3)
|
8
10
|
thor (~> 0.1)
|
9
11
|
yard (~> 0.9)
|
@@ -15,12 +17,13 @@ GEM
|
|
15
17
|
addressable (2.7.0)
|
16
18
|
public_suffix (>= 2.0.2, < 5.0)
|
17
19
|
afm (0.2.2)
|
20
|
+
concurrent-ruby (1.1.6)
|
18
21
|
declarative (0.0.10)
|
19
22
|
declarative-option (0.1.0)
|
20
|
-
faraday (0.
|
23
|
+
faraday (1.0.1)
|
21
24
|
multipart-post (>= 1.2, < 3)
|
22
25
|
fastimage (2.1.7)
|
23
|
-
google-api-client (0.
|
26
|
+
google-api-client (0.40.0)
|
24
27
|
addressable (~> 2.5, >= 2.5.1)
|
25
28
|
googleauth (~> 0.9)
|
26
29
|
httpclient (>= 2.8.1, < 3.0)
|
@@ -28,44 +31,58 @@ GEM
|
|
28
31
|
representable (~> 3.0)
|
29
32
|
retriable (>= 2.0, < 4.0)
|
30
33
|
signet (~> 0.12)
|
31
|
-
|
32
|
-
|
34
|
+
google-cloud-bigquery (1.21.1)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
google-api-client (~> 0.33)
|
37
|
+
google-cloud-core (~> 1.2)
|
38
|
+
googleauth (~> 0.9)
|
39
|
+
mini_mime (~> 1.0)
|
40
|
+
google-cloud-core (1.5.0)
|
41
|
+
google-cloud-env (~> 1.0)
|
42
|
+
google-cloud-errors (~> 1.0)
|
43
|
+
google-cloud-env (1.3.2)
|
44
|
+
faraday (>= 0.17.3, < 2.0)
|
45
|
+
google-cloud-errors (1.0.1)
|
46
|
+
googleauth (0.12.0)
|
47
|
+
faraday (>= 0.17.3, < 2.0)
|
33
48
|
jwt (>= 1.4, < 3.0)
|
34
49
|
memoist (~> 0.16)
|
35
50
|
multi_json (~> 1.11)
|
36
51
|
os (>= 0.9, < 2.0)
|
37
|
-
signet (~> 0.
|
52
|
+
signet (~> 0.14)
|
38
53
|
hashery (2.1.2)
|
39
54
|
httpclient (2.8.3)
|
55
|
+
i18n (1.8.2)
|
56
|
+
concurrent-ruby (~> 1.0)
|
40
57
|
jwt (2.2.1)
|
41
58
|
memoist (0.16.2)
|
42
59
|
mini_mime (1.0.2)
|
43
60
|
multi_json (1.14.1)
|
44
61
|
multipart-post (2.1.1)
|
45
|
-
os (1.0
|
62
|
+
os (1.1.0)
|
46
63
|
pdf-reader (2.4.0)
|
47
64
|
Ascii85 (~> 1.0.0)
|
48
65
|
afm (~> 0.2.1)
|
49
66
|
hashery (~> 2.0)
|
50
67
|
ruby-rc4
|
51
68
|
ttfunk
|
52
|
-
public_suffix (4.0.
|
53
|
-
rake (
|
69
|
+
public_suffix (4.0.5)
|
70
|
+
rake (13.0.1)
|
54
71
|
representable (3.0.4)
|
55
72
|
declarative (< 0.1.0)
|
56
73
|
declarative-option (< 0.2.0)
|
57
74
|
uber (< 0.2.0)
|
58
75
|
retriable (3.1.2)
|
59
76
|
ruby-rc4 (0.1.5)
|
60
|
-
signet (0.
|
77
|
+
signet (0.14.0)
|
61
78
|
addressable (~> 2.3)
|
62
|
-
faraday (
|
79
|
+
faraday (>= 0.17.3, < 2.0)
|
63
80
|
jwt (>= 1.5, < 3.0)
|
64
81
|
multi_json (~> 1.10)
|
65
82
|
thor (0.20.3)
|
66
|
-
ttfunk (1.
|
83
|
+
ttfunk (1.6.2.1)
|
67
84
|
uber (0.1.0)
|
68
|
-
yard (0.9.
|
85
|
+
yard (0.9.25)
|
69
86
|
|
70
87
|
PLATFORMS
|
71
88
|
ruby
|
@@ -73,7 +90,7 @@ PLATFORMS
|
|
73
90
|
DEPENDENCIES
|
74
91
|
arquivo!
|
75
92
|
bundler (~> 1.17)
|
76
|
-
rake
|
93
|
+
rake
|
77
94
|
|
78
95
|
BUNDLED WITH
|
79
|
-
1.17.
|
96
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Arquivo
|
2
2
|
|
3
|
-
Processa documentos do condominio ph1341c118 para arquivo. Pode tambem segmentar PDFs e MINUTAS. Tendo os documentos em pastas separadas, pode ainda criar arquivos apropriados.
|
3
|
+
Processa documentos do condominio ph1341c118 para arquivo. Pode tambem segmentar PDFs e MINUTAS. Tendo os documentos em pastas separadas, pode ainda criar arquivos apropriados. Parmite ainda processar dados do condominio ph1341c118 no bigquery para arquivo historico.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
data/arquivo.gemspec
CHANGED
@@ -34,10 +34,12 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.require_paths = ['lib']
|
35
35
|
|
36
36
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
37
|
-
spec.add_development_dependency 'rake'
|
37
|
+
spec.add_development_dependency 'rake'
|
38
38
|
|
39
39
|
spec.add_dependency 'fastimage', '~> 2.1'
|
40
40
|
spec.add_dependency 'google-api-client', '~> 0.34'
|
41
|
+
spec.add_dependency 'google-cloud-bigquery'
|
42
|
+
spec.add_dependency 'i18n'
|
41
43
|
spec.add_dependency 'pdf-reader', '~> 2.3'
|
42
44
|
spec.add_dependency 'thor', '~> 0.1'
|
43
45
|
spec.add_dependency 'yard', '~> 0.9'
|
data/lib/arquivo.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'thor'
|
4
4
|
require 'arquivo/version'
|
5
|
+
require 'arquivo/sheets'
|
6
|
+
require 'arquivo/bigquery'
|
5
7
|
require 'arquivo/dir'
|
6
8
|
require 'arquivo/pdf'
|
7
9
|
require 'arquivo/jpg'
|
@@ -64,6 +66,12 @@ module Arquivo
|
|
64
66
|
C118pdf.new(dashboard, options).faz_dashboard
|
65
67
|
end
|
66
68
|
|
69
|
+
desc 'big', 'processa dados bigquery c118'
|
70
|
+
# processa bigquery c118
|
71
|
+
def big
|
72
|
+
C118bigquery.new.processa_big
|
73
|
+
end
|
74
|
+
|
67
75
|
desc 'dir PASTA', 'processa faturas/recibos/extratos/minutas ' \
|
68
76
|
'e cria arquivos c118'
|
69
77
|
option :fuzz, type: :numeric, default: 29,
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'google/cloud/bigquery'
|
4
|
+
|
5
|
+
module Arquivo
|
6
|
+
# permite arquivar dados c118 no bigquery
|
7
|
+
class C118bigquery < C118sheets
|
8
|
+
# @return [Google::Cloud::Bigquery] API bigquery c118
|
9
|
+
attr_reader :big
|
10
|
+
|
11
|
+
# @return [C118bigquery] acesso bigquery c118
|
12
|
+
def initialize
|
13
|
+
# inicializar API sheets com ID cliente & credenciais
|
14
|
+
sheets_credentials
|
15
|
+
|
16
|
+
# This uses Application Default Credentials to authenticate.
|
17
|
+
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
18
|
+
@big = Google::Cloud::Bigquery.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# obtem dados da folha c118 & processa no bigquery
|
22
|
+
def processa_big
|
23
|
+
# folha c118-contas
|
24
|
+
s = '1PbiMrtTtqGztZMhe3AiJbDS6NQE9o3hXebnQEFdt954'
|
25
|
+
a = folhas.get_spreadsheet_values(s, 'cbd!AJ2')
|
26
|
+
.values.flatten[0]
|
27
|
+
i = folhas.get_spreadsheet_values(s, 'bal!R2:R')
|
28
|
+
.values.flatten.join(',')
|
29
|
+
puts 'processamento bigquery feito para ano ' + a +
|
30
|
+
": [del_bal,del_hise,ins_bal,ins_hise] #{sql_big(a, i)}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# executa comandos DML (Data Manipulation Language) no bigquery
|
34
|
+
#
|
35
|
+
# @return [Array<Integer>] numero linhas afetadas pelos DMLs
|
36
|
+
def sql_big(ano, lst)
|
37
|
+
[dml('delete FROM arquivo.bal WHERE ano=' + ano),
|
38
|
+
dml('delete FROM arquivo.hise WHERE ano=' + ano),
|
39
|
+
dml('INSERT arquivo.bal (data,entidade,documento,descricao,valor,tag,' \
|
40
|
+
'dr,banco,conta,ano,id4,dref,daa,paga,desb) VALUES' + lst),
|
41
|
+
dml('INSERT arquivo.hise(ano,dr,tag,descricao,valor) ' \
|
42
|
+
'select * from arquivo.vhe where ano=' + ano)]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Integer] numero linhas afetadas pelo DML
|
46
|
+
def dml(sql)
|
47
|
+
job = big.query_job(sql)
|
48
|
+
job.wait_until_done!
|
49
|
+
puts job.error if job.failed?
|
50
|
+
job.num_dml_affected_rows
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/arquivo/dir.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'google/apis/sheets_v4'
|
4
|
-
require 'googleauth'
|
5
|
-
require 'googleauth/stores/file_token_store'
|
6
|
-
|
7
3
|
require 'arquivo/noise'
|
8
4
|
|
9
5
|
module Arquivo
|
@@ -73,49 +69,20 @@ module Arquivo
|
|
73
69
|
@item = nil
|
74
70
|
end
|
75
71
|
|
76
|
-
# @!group dados
|
77
|
-
# @return [Hash] dados oficiais para
|
72
|
+
# @!group dados folhas-calculo c118
|
73
|
+
# @return [Hash] dados oficiais para classificacao de faturas e recibos
|
78
74
|
def obtem_dados
|
79
75
|
@dados = {}
|
80
76
|
# somente faturas e recibos necessitam reclassificacao
|
81
77
|
return unless %i[fft frc].include?(contem)
|
82
78
|
|
83
|
-
#
|
84
|
-
|
85
|
-
@dados =
|
86
|
-
|
79
|
+
# folha c118-contas
|
80
|
+
s = '1PbiMrtTtqGztZMhe3AiJbDS6NQE9o3hXebnQEFdt954'
|
81
|
+
@dados = C118sheets.new.folhas
|
82
|
+
.get_spreadsheet_values(s, contem.to_s + '!A2:E')
|
83
|
+
.values.group_by { |k| k[0][/\w+/] }
|
87
84
|
rescue StandardError
|
88
85
|
@dados = {}
|
89
86
|
end
|
90
|
-
|
91
|
-
# assegura credenciais validas, obtidas dum ficheiro de credencias
|
92
|
-
#
|
93
|
-
# @return [Google::Apis::SheetsV4::SheetsService] c118 sheets_v4
|
94
|
-
def c118_sheets
|
95
|
-
p = '/home/c118/c118-'
|
96
|
-
# file obtido console.cloud.google.com/apis OAuth 2.0 client IDs
|
97
|
-
i = Google::Auth::ClientId.from_file("#{p}credentials.json")
|
98
|
-
s = Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
|
99
|
-
# file criado aquando new_credentials is executed
|
100
|
-
f = Google::Auth::Stores::FileTokenStore.new(file: "#{p}token.yaml")
|
101
|
-
z = Google::Auth::UserAuthorizer.new(i, s, f)
|
102
|
-
|
103
|
-
sheets = Google::Apis::SheetsV4::SheetsService.new
|
104
|
-
sheets.client_options.application_name = 'c118-arquivo'
|
105
|
-
sheets.authorization = z.get_credentials('default') ||
|
106
|
-
new_credentials(z, 'urn:ietf:wg:oauth:2.0:oob')
|
107
|
-
sheets
|
108
|
-
end
|
109
|
-
|
110
|
-
# inicializar OAuth2 authorization abrindo URL e copiando novo codigo
|
111
|
-
#
|
112
|
-
# @return [Google::Auth::UserAuthorizer] OAuth2 credentials
|
113
|
-
def new_credentials(aut, oob)
|
114
|
-
puts 'Open URL and copy code after authorization, in <codigo-aqui>',
|
115
|
-
aut.get_authorization_url(base_url: oob)
|
116
|
-
aut.get_and_store_credentials_from_code(user_id: 'default',
|
117
|
-
code: '<codigo-aqui>',
|
118
|
-
base_url: oob)
|
119
|
-
end
|
120
87
|
end
|
121
88
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'google/apis/sheets_v4'
|
4
|
+
require 'googleauth'
|
5
|
+
require 'googleauth/stores/file_token_store'
|
6
|
+
|
7
|
+
module Arquivo
|
8
|
+
# acede a folhas-calculo c118
|
9
|
+
class C118sheets
|
10
|
+
# @return (see #sheets_credentials)
|
11
|
+
attr_reader :folhas
|
12
|
+
|
13
|
+
# @return [C118sheets] acesso folhas-calculo c118
|
14
|
+
def initialize
|
15
|
+
sheets_credentials
|
16
|
+
end
|
17
|
+
|
18
|
+
# inicializar API sheets com ID cliente & credenciais
|
19
|
+
#
|
20
|
+
# @return [Google::Apis::SheetsV4::SheetsService] API folhas-calculo c118
|
21
|
+
def sheets_credentials
|
22
|
+
l = '/home/c118/.sheets.'
|
23
|
+
# file obtido console.cloud.google.com/apis OAuth 2.0 client IDs
|
24
|
+
i = Google::Auth::ClientId.from_file(l + 'json')
|
25
|
+
s = Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
|
26
|
+
# file criado aquando new_credentials is executed
|
27
|
+
f = Google::Auth::Stores::FileTokenStore.new(file: l + 'yaml')
|
28
|
+
z = Google::Auth::UserAuthorizer.new(i, s, f)
|
29
|
+
@folhas = Google::Apis::SheetsV4::SheetsService.new
|
30
|
+
@folhas.client_options.application_name = 'c118-arquivo'
|
31
|
+
@folhas.authorization = z.get_credentials('default') ||
|
32
|
+
new_credentials(z, 'urn:ietf:wg:oauth:2.0:oob')
|
33
|
+
end
|
34
|
+
|
35
|
+
# inicializar OAuth2 authorization abrindo URL e copiando novo codigo
|
36
|
+
#
|
37
|
+
# @return [Google::Auth::UserAuthorizer] OAuth2 credentials
|
38
|
+
def new_credentials(aut, oob)
|
39
|
+
puts 'Open URL and copy code after authorization, in <codigo-aqui>',
|
40
|
+
aut.get_authorization_url(base_url: oob)
|
41
|
+
aut.get_and_store_credentials_from_code(user_id: 'default',
|
42
|
+
code: '<codigo-aqui>',
|
43
|
+
base_url: oob)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/arquivo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arquivo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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-01
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: fastimage
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.34'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: google-cloud-bigquery
|
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: i18n
|
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'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: pdf-reader
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,12 +157,14 @@ files:
|
|
129
157
|
- bin/setup
|
130
158
|
- exe/arquivo
|
131
159
|
- lib/arquivo.rb
|
160
|
+
- lib/arquivo/bigquery.rb
|
132
161
|
- lib/arquivo/dir.rb
|
133
162
|
- lib/arquivo/extrato.rb
|
134
163
|
- lib/arquivo/jpg.rb
|
135
164
|
- lib/arquivo/mp3.rb
|
136
165
|
- lib/arquivo/noise.rb
|
137
166
|
- lib/arquivo/pdf.rb
|
167
|
+
- lib/arquivo/sheets.rb
|
138
168
|
- lib/arquivo/version.rb
|
139
169
|
homepage: https://github.com/ph1341c118/arquivo
|
140
170
|
licenses:
|
@@ -157,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
187
|
- !ruby/object:Gem::Version
|
158
188
|
version: '0'
|
159
189
|
requirements: []
|
160
|
-
rubygems_version: 3.0.
|
190
|
+
rubygems_version: 3.0.8
|
161
191
|
signing_key:
|
162
192
|
specification_version: 4
|
163
193
|
summary: Processa documentos do condominio ph1341c118 para arquivo.
|