arquivo 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/README.md +1 -1
- data/arquivo.gemspec +1 -0
- data/lib/arquivo.rb +3 -1
- data/lib/arquivo/bigquery.rb +53 -0
- data/lib/arquivo/dir.rb +7 -58
- data/lib/arquivo/sheets.rb +46 -0
- data/lib/arquivo/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d1c0b7dca23809705a05ea4e6bd704e99eeab5fc27381c780d8aa32a84da10
|
4
|
+
data.tar.gz: 68b6dda1b3beb4ca52117df535be8885c80e0c3487679feab337aa47d0296306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 487f95c662296e02d160317dcd22f391182d0561a4cab341198649f05f3d88e35a9284804a72110338e15451bc7a26117180afa5f07148da23cef2147207f8ef
|
7
|
+
data.tar.gz: d03ca2a02cbab924c791c047103b05bae704ac3d5d9209fa0eae17ae5d3168e99839c173c03a5103968414a68b5d223ff141ba7abde62dec696f5e104b7cb5b5
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arquivo (0.2.
|
4
|
+
arquivo (0.2.8)
|
5
5
|
fastimage (~> 2.1)
|
6
6
|
google-api-client (~> 0.34)
|
7
7
|
google-cloud-bigquery
|
8
|
+
i18n
|
8
9
|
pdf-reader (~> 2.3)
|
9
10
|
thor (~> 0.1)
|
10
11
|
yard (~> 0.9)
|
@@ -51,6 +52,8 @@ GEM
|
|
51
52
|
signet (~> 0.12)
|
52
53
|
hashery (2.1.2)
|
53
54
|
httpclient (2.8.3)
|
55
|
+
i18n (1.8.2)
|
56
|
+
concurrent-ruby (~> 1.0)
|
54
57
|
jwt (2.2.1)
|
55
58
|
memoist (0.16.2)
|
56
59
|
mini_mime (1.0.2)
|
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
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_dependency 'fastimage', '~> 2.1'
|
40
40
|
spec.add_dependency 'google-api-client', '~> 0.34'
|
41
41
|
spec.add_dependency 'google-cloud-bigquery'
|
42
|
+
spec.add_dependency 'i18n'
|
42
43
|
spec.add_dependency 'pdf-reader', '~> 2.3'
|
43
44
|
spec.add_dependency 'thor', '~> 0.1'
|
44
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'
|
@@ -67,7 +69,7 @@ module Arquivo
|
|
67
69
|
desc 'big', 'processa dados bigquery c118'
|
68
70
|
# processa bigquery c118
|
69
71
|
def big
|
70
|
-
|
72
|
+
C118bigquery.new.processa_big
|
71
73
|
end
|
72
74
|
|
73
75
|
desc 'dir PASTA', 'processa faturas/recibos/extratos/minutas ' \
|
@@ -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,10 +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
|
-
require 'google/cloud/bigquery'
|
7
|
-
|
8
3
|
require 'arquivo/noise'
|
9
4
|
|
10
5
|
module Arquivo
|
@@ -67,23 +62,6 @@ module Arquivo
|
|
67
62
|
processa_items
|
68
63
|
end
|
69
64
|
|
70
|
-
def processa_big
|
71
|
-
# sheet c118-contas
|
72
|
-
dg = '1PbiMrtTtqGztZMhe3AiJbDS6NQE9o3hXebnQEFdt954'
|
73
|
-
ano = c118_sheets.get_spreadsheet_values(dg, 'cdb!AJ2').values
|
74
|
-
ins = c118_sheets.get_spreadsheet_values(dg, 'cbd!AJ:AJ').values
|
75
|
-
puts ano
|
76
|
-
puts ins
|
77
|
-
|
78
|
-
# This uses Application Default Credentials to authenticate.
|
79
|
-
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
80
|
-
# bigquery = Google::Cloud::Bigquery.new
|
81
|
-
# r = bigquery.query 'select * from arquivo.bal order by 1 desc limit 10'
|
82
|
-
# r.each do |row|
|
83
|
-
# puts "#{row[:data]}: #{row[:documento]}"
|
84
|
-
# end
|
85
|
-
end
|
86
|
-
|
87
65
|
# @return [String] proximo item dentro da pasta
|
88
66
|
def next_item
|
89
67
|
@item = items.next
|
@@ -91,49 +69,20 @@ module Arquivo
|
|
91
69
|
@item = nil
|
92
70
|
end
|
93
71
|
|
94
|
-
# @!group dados
|
95
|
-
# @return [Hash] dados oficiais para
|
72
|
+
# @!group dados folhas-calculo c118
|
73
|
+
# @return [Hash] dados oficiais para classificacao de faturas e recibos
|
96
74
|
def obtem_dados
|
97
75
|
@dados = {}
|
98
76
|
# somente faturas e recibos necessitam reclassificacao
|
99
77
|
return unless %i[fft frc].include?(contem)
|
100
78
|
|
101
|
-
#
|
102
|
-
|
103
|
-
@dados =
|
104
|
-
|
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+/] }
|
105
84
|
rescue StandardError
|
106
85
|
@dados = {}
|
107
86
|
end
|
108
|
-
|
109
|
-
# assegura credenciais validas, obtidas dum ficheiro de credencias
|
110
|
-
#
|
111
|
-
# @return [Google::Apis::SheetsV4::SheetsService] c118 sheets_v4
|
112
|
-
def c118_sheets
|
113
|
-
p = '/home/c118/.'
|
114
|
-
# file obtido console.cloud.google.com/apis OAuth 2.0 client IDs
|
115
|
-
i = Google::Auth::ClientId.from_file("#{p}sheets.json")
|
116
|
-
s = Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
|
117
|
-
# file criado aquando new_credentials is executed
|
118
|
-
f = Google::Auth::Stores::FileTokenStore.new(file: "#{p}sheets.yaml")
|
119
|
-
z = Google::Auth::UserAuthorizer.new(i, s, f)
|
120
|
-
|
121
|
-
sheets = Google::Apis::SheetsV4::SheetsService.new
|
122
|
-
sheets.client_options.application_name = 'c118-arquivo'
|
123
|
-
sheets.authorization = z.get_credentials('default') ||
|
124
|
-
new_credentials(z, 'urn:ietf:wg:oauth:2.0:oob')
|
125
|
-
sheets
|
126
|
-
end
|
127
|
-
|
128
|
-
# inicializar OAuth2 authorization abrindo URL e copiando novo codigo
|
129
|
-
#
|
130
|
-
# @return [Google::Auth::UserAuthorizer] OAuth2 credentials
|
131
|
-
def new_credentials(aut, oob)
|
132
|
-
puts 'Open URL and copy code after authorization, in <codigo-aqui>',
|
133
|
-
aut.get_authorization_url(base_url: oob)
|
134
|
-
aut.get_and_store_credentials_from_code(user_id: 'default',
|
135
|
-
code: '<codigo-aqui>',
|
136
|
-
base_url: oob)
|
137
|
-
end
|
138
87
|
end
|
139
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.8
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
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'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: pdf-reader
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,12 +157,14 @@ files:
|
|
143
157
|
- bin/setup
|
144
158
|
- exe/arquivo
|
145
159
|
- lib/arquivo.rb
|
160
|
+
- lib/arquivo/bigquery.rb
|
146
161
|
- lib/arquivo/dir.rb
|
147
162
|
- lib/arquivo/extrato.rb
|
148
163
|
- lib/arquivo/jpg.rb
|
149
164
|
- lib/arquivo/mp3.rb
|
150
165
|
- lib/arquivo/noise.rb
|
151
166
|
- lib/arquivo/pdf.rb
|
167
|
+
- lib/arquivo/sheets.rb
|
152
168
|
- lib/arquivo/version.rb
|
153
169
|
homepage: https://github.com/ph1341c118/arquivo
|
154
170
|
licenses:
|