arquivo 0.2.6 → 0.3.2
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 +4 -2
- data/Gemfile.lock +81 -38
- data/README.md +1 -1
- data/Rakefile +4 -2
- data/arquivo.gemspec +9 -10
- data/bin/console +4 -3
- data/lib/arquivo.rb +17 -24
- data/lib/arquivo/bigquery.rb +60 -0
- data/lib/arquivo/dir.rb +7 -53
- data/lib/arquivo/extrato.rb +1 -17
- data/lib/arquivo/mp3.rb +1 -2
- data/lib/arquivo/noise.rb +4 -11
- data/lib/arquivo/pdf.rb +16 -1
- data/lib/arquivo/sheets.rb +42 -0
- data/lib/arquivo/version.rb +1 -1
- metadata +43 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 547b4cad2f4ea892ba11aa96d948d6569030753a403c830048371f0e45451624
|
|
4
|
+
data.tar.gz: '08987d485a880f786f0264775c49fe2c731bc097ef09bd983b0dc205ef9c6daf'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc17a7e507868ac122ddb52269e39e5e8c4f87e256dc83c4a31e2f7d43a63a6d97e3cfe49c423ba574c7fe6c6246b4baf5e3af56d8f2657f90e29f7ea1e4c2bc
|
|
7
|
+
data.tar.gz: aa28b40ef8b46de80c0f4a048ec0a1897dd5b07490814c0fd6604ea0936cddd91a6fdfe704a810fd678be77230c90d7e9965ccced42954e87dc51d395828d9ea
|
data/Gemfile
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
4
6
|
|
|
5
7
|
# Specify your gem's dependencies in arquivo.gemspec
|
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
|
@@ -1,93 +1,136 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
arquivo (0.2
|
|
5
|
-
fastimage
|
|
6
|
-
google-api-client
|
|
4
|
+
arquivo (0.3.2)
|
|
5
|
+
fastimage
|
|
6
|
+
google-api-client
|
|
7
7
|
google-cloud-bigquery
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
i18n
|
|
9
|
+
pdf-reader
|
|
10
|
+
thor
|
|
11
|
+
yard
|
|
11
12
|
|
|
12
13
|
GEM
|
|
13
14
|
remote: https://rubygems.org/
|
|
14
15
|
specs:
|
|
15
|
-
Ascii85 (1.0
|
|
16
|
+
Ascii85 (1.1.0)
|
|
17
|
+
activesupport (6.1.3.2)
|
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
|
+
i18n (>= 1.6, < 2)
|
|
20
|
+
minitest (>= 5.1)
|
|
21
|
+
tzinfo (~> 2.0)
|
|
22
|
+
zeitwerk (~> 2.3)
|
|
16
23
|
addressable (2.7.0)
|
|
17
24
|
public_suffix (>= 2.0.2, < 5.0)
|
|
18
25
|
afm (0.2.2)
|
|
19
|
-
concurrent-ruby (1.1.
|
|
20
|
-
declarative (0.0.
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
concurrent-ruby (1.1.8)
|
|
27
|
+
declarative (0.0.20)
|
|
28
|
+
faraday (1.4.2)
|
|
29
|
+
faraday-em_http (~> 1.0)
|
|
30
|
+
faraday-em_synchrony (~> 1.0)
|
|
31
|
+
faraday-excon (~> 1.1)
|
|
32
|
+
faraday-net_http (~> 1.0)
|
|
33
|
+
faraday-net_http_persistent (~> 1.1)
|
|
23
34
|
multipart-post (>= 1.2, < 3)
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
ruby2_keywords (>= 0.0.4)
|
|
36
|
+
faraday-em_http (1.0.0)
|
|
37
|
+
faraday-em_synchrony (1.0.0)
|
|
38
|
+
faraday-excon (1.1.0)
|
|
39
|
+
faraday-net_http (1.0.1)
|
|
40
|
+
faraday-net_http_persistent (1.1.0)
|
|
41
|
+
fastimage (2.2.4)
|
|
42
|
+
gems (1.2.0)
|
|
43
|
+
google-api-client (0.53.0)
|
|
44
|
+
google-apis-core (~> 0.1)
|
|
45
|
+
google-apis-generator (~> 0.1)
|
|
46
|
+
google-apis-bigquery_v2 (0.12.0)
|
|
47
|
+
google-apis-core (~> 0.1)
|
|
48
|
+
google-apis-core (0.3.0)
|
|
26
49
|
addressable (~> 2.5, >= 2.5.1)
|
|
27
|
-
googleauth (~> 0.
|
|
50
|
+
googleauth (~> 0.14)
|
|
28
51
|
httpclient (>= 2.8.1, < 3.0)
|
|
29
52
|
mini_mime (~> 1.0)
|
|
30
53
|
representable (~> 3.0)
|
|
31
54
|
retriable (>= 2.0, < 4.0)
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
rexml
|
|
56
|
+
signet (~> 0.14)
|
|
57
|
+
webrick
|
|
58
|
+
google-apis-discovery_v1 (0.4.0)
|
|
59
|
+
google-apis-core (~> 0.1)
|
|
60
|
+
google-apis-generator (0.3.0)
|
|
61
|
+
activesupport (>= 5.0)
|
|
62
|
+
gems (~> 1.2)
|
|
63
|
+
google-apis-core (~> 0.1)
|
|
64
|
+
google-apis-discovery_v1 (~> 0.0)
|
|
65
|
+
thor (>= 0.20, < 2.a)
|
|
66
|
+
google-cloud-bigquery (1.31.0)
|
|
34
67
|
concurrent-ruby (~> 1.0)
|
|
35
|
-
google-
|
|
68
|
+
google-apis-bigquery_v2 (~> 0.1)
|
|
36
69
|
google-cloud-core (~> 1.2)
|
|
37
70
|
googleauth (~> 0.9)
|
|
38
71
|
mini_mime (~> 1.0)
|
|
39
|
-
google-cloud-core (1.
|
|
72
|
+
google-cloud-core (1.6.0)
|
|
40
73
|
google-cloud-env (~> 1.0)
|
|
41
74
|
google-cloud-errors (~> 1.0)
|
|
42
|
-
google-cloud-env (1.
|
|
75
|
+
google-cloud-env (1.5.0)
|
|
43
76
|
faraday (>= 0.17.3, < 2.0)
|
|
44
|
-
google-cloud-errors (1.
|
|
45
|
-
googleauth (0.
|
|
77
|
+
google-cloud-errors (1.1.0)
|
|
78
|
+
googleauth (0.16.2)
|
|
46
79
|
faraday (>= 0.17.3, < 2.0)
|
|
47
80
|
jwt (>= 1.4, < 3.0)
|
|
48
81
|
memoist (~> 0.16)
|
|
49
82
|
multi_json (~> 1.11)
|
|
50
83
|
os (>= 0.9, < 2.0)
|
|
51
|
-
signet (~> 0.
|
|
84
|
+
signet (~> 0.14)
|
|
52
85
|
hashery (2.1.2)
|
|
53
86
|
httpclient (2.8.3)
|
|
54
|
-
|
|
87
|
+
i18n (1.8.10)
|
|
88
|
+
concurrent-ruby (~> 1.0)
|
|
89
|
+
jwt (2.2.3)
|
|
55
90
|
memoist (0.16.2)
|
|
56
|
-
mini_mime (1.0
|
|
57
|
-
|
|
91
|
+
mini_mime (1.1.0)
|
|
92
|
+
minitest (5.14.4)
|
|
93
|
+
multi_json (1.15.0)
|
|
58
94
|
multipart-post (2.1.1)
|
|
59
|
-
os (1.1.
|
|
60
|
-
pdf-reader (2.4.
|
|
61
|
-
Ascii85 (~> 1.0
|
|
95
|
+
os (1.1.1)
|
|
96
|
+
pdf-reader (2.4.2)
|
|
97
|
+
Ascii85 (~> 1.0)
|
|
62
98
|
afm (~> 0.2.1)
|
|
63
99
|
hashery (~> 2.0)
|
|
64
100
|
ruby-rc4
|
|
65
101
|
ttfunk
|
|
66
|
-
public_suffix (4.0.
|
|
67
|
-
rake (13.0.
|
|
68
|
-
representable (3.
|
|
102
|
+
public_suffix (4.0.6)
|
|
103
|
+
rake (13.0.3)
|
|
104
|
+
representable (3.1.1)
|
|
69
105
|
declarative (< 0.1.0)
|
|
70
|
-
|
|
106
|
+
trailblazer-option (>= 0.1.1, < 0.2.0)
|
|
71
107
|
uber (< 0.2.0)
|
|
72
108
|
retriable (3.1.2)
|
|
109
|
+
rexml (3.2.5)
|
|
73
110
|
ruby-rc4 (0.1.5)
|
|
74
|
-
|
|
111
|
+
ruby2_keywords (0.0.4)
|
|
112
|
+
signet (0.15.0)
|
|
75
113
|
addressable (~> 2.3)
|
|
76
114
|
faraday (>= 0.17.3, < 2.0)
|
|
77
115
|
jwt (>= 1.5, < 3.0)
|
|
78
116
|
multi_json (~> 1.10)
|
|
79
|
-
thor (
|
|
80
|
-
|
|
117
|
+
thor (1.1.0)
|
|
118
|
+
trailblazer-option (0.1.1)
|
|
119
|
+
ttfunk (1.7.0)
|
|
120
|
+
tzinfo (2.0.4)
|
|
121
|
+
concurrent-ruby (~> 1.0)
|
|
81
122
|
uber (0.1.0)
|
|
82
|
-
|
|
123
|
+
webrick (1.7.0)
|
|
124
|
+
yard (0.9.26)
|
|
125
|
+
zeitwerk (2.4.2)
|
|
83
126
|
|
|
84
127
|
PLATFORMS
|
|
85
128
|
ruby
|
|
86
129
|
|
|
87
130
|
DEPENDENCIES
|
|
88
131
|
arquivo!
|
|
89
|
-
bundler
|
|
132
|
+
bundler
|
|
90
133
|
rake
|
|
91
134
|
|
|
92
135
|
BUNDLED WITH
|
|
93
|
-
|
|
136
|
+
2.2.19
|
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/Rakefile
CHANGED
data/arquivo.gemspec
CHANGED
|
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.email = ['hernanirvaz@gmail.com']
|
|
12
12
|
spec.homepage = 'https://github.com/ph1341c118/arquivo'
|
|
13
13
|
|
|
14
|
-
spec.summary = 'Processa documentos do condominio ph1341c118 '
|
|
15
|
-
'para arquivo.'
|
|
14
|
+
spec.summary = 'Processa documentos do condominio ph1341c118 para arquivo.'
|
|
16
15
|
spec.description = spec.summary
|
|
17
16
|
spec.description += ' Pode tambem segmentar PDFs e MINUTAS. ' \
|
|
18
17
|
'Tendo os documentos em pastas separadas, pode ainda ' \
|
|
@@ -26,20 +25,20 @@ Gem::Specification.new do |spec|
|
|
|
26
25
|
# The `git ls-files -z` loads the files in the
|
|
27
26
|
# RubyGem that have been added into git.
|
|
28
27
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
29
|
-
`git ls-files -z`.split("\x0")
|
|
30
|
-
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
31
29
|
end
|
|
32
30
|
spec.bindir = 'exe'
|
|
33
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
34
32
|
spec.require_paths = ['lib']
|
|
35
33
|
|
|
36
|
-
spec.add_development_dependency 'bundler'
|
|
34
|
+
spec.add_development_dependency 'bundler'
|
|
37
35
|
spec.add_development_dependency 'rake'
|
|
38
36
|
|
|
39
|
-
spec.add_dependency 'fastimage'
|
|
40
|
-
spec.add_dependency 'google-api-client'
|
|
37
|
+
spec.add_dependency 'fastimage'
|
|
38
|
+
spec.add_dependency 'google-api-client'
|
|
41
39
|
spec.add_dependency 'google-cloud-bigquery'
|
|
42
|
-
spec.add_dependency '
|
|
43
|
-
spec.add_dependency '
|
|
44
|
-
spec.add_dependency '
|
|
40
|
+
spec.add_dependency 'i18n'
|
|
41
|
+
spec.add_dependency 'pdf-reader'
|
|
42
|
+
spec.add_dependency 'thor'
|
|
43
|
+
spec.add_dependency 'yard'
|
|
45
44
|
end
|
data/bin/console
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'arquivo'
|
|
5
6
|
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -10,5 +11,5 @@ require "arquivo"
|
|
|
10
11
|
# require "pry"
|
|
11
12
|
# Pry.start
|
|
12
13
|
|
|
13
|
-
require
|
|
14
|
+
require 'irb'
|
|
14
15
|
IRB.start(__FILE__)
|
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'
|
|
@@ -17,10 +19,8 @@ module Arquivo
|
|
|
17
19
|
|
|
18
20
|
# @abstract CLI tarefas segmentar e arquivar
|
|
19
21
|
class CLI < Thor
|
|
20
|
-
desc 'mp3 MINUTA', 'processa MINUTA criando pasta '
|
|
21
|
-
|
|
22
|
-
option :tempos, type: :array, default: [],
|
|
23
|
-
desc: 'lista tempos para segmentar MINUTA, ex: [[h:]m:]s'
|
|
22
|
+
desc 'mp3 MINUTA', 'processa MINUTA criando pasta com segmentos para arquivo'
|
|
23
|
+
option :tempos, type: :array, default: [], desc: 'lista tempos para segmentar MINUTA, ex: [[h:]m:]s'
|
|
24
24
|
# segmenta minuta segundo lista tempos
|
|
25
25
|
#
|
|
26
26
|
# @param [String] minuta ficheiro audio a segmentar
|
|
@@ -34,15 +34,14 @@ module Arquivo
|
|
|
34
34
|
f.segmenta_minuta(options[:tempos])
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
desc 'pdf EXTRATO', 'processa EXTRATO criando pasta '
|
|
38
|
-
'com documentos para arquivo'
|
|
37
|
+
desc 'pdf EXTRATO', 'processa EXTRATO criando pasta com documentos para arquivo'
|
|
39
38
|
# segmenta extrato limpando publicidade
|
|
40
39
|
#
|
|
41
40
|
# @param [String] extrato pdf a segmentar
|
|
42
41
|
def pdf(extrato)
|
|
43
42
|
return unless File.exist?(extrato) && File.ftype(extrato) == 'file'
|
|
44
43
|
|
|
45
|
-
f = C118pdf.new(extrato,
|
|
44
|
+
f = C118pdf.new(extrato, {})
|
|
46
45
|
return unless f.processa_extrato?
|
|
47
46
|
|
|
48
47
|
system "mkdir -p #{f.base}"
|
|
@@ -61,31 +60,25 @@ module Arquivo
|
|
|
61
60
|
def dsh(dashboard)
|
|
62
61
|
return unless File.exist?(dashboard) && File.ftype(dashboard) == 'file'
|
|
63
62
|
|
|
64
|
-
C118pdf.new(dashboard,
|
|
63
|
+
C118pdf.new(dashboard, {}).faz_dashboard
|
|
65
64
|
end
|
|
66
65
|
|
|
67
66
|
desc 'big', 'processa dados bigquery c118'
|
|
68
67
|
# processa bigquery c118
|
|
69
68
|
def big
|
|
70
|
-
|
|
69
|
+
C118bigquery.new.processa_big
|
|
71
70
|
end
|
|
72
71
|
|
|
73
|
-
desc 'dir PASTA', 'processa faturas/recibos/extratos/minutas '
|
|
74
|
-
|
|
75
|
-
option :fuzz,
|
|
76
|
-
|
|
77
|
-
option :quality, type: :numeric, default: 15,
|
|
78
|
-
desc: 'compress jpg N% -> scanned pdf (less=low quality)'
|
|
72
|
+
desc 'dir PASTA', 'processa faturas/recibos/extratos/minutas e cria arquivos c118'
|
|
73
|
+
# opcoes para compressao de imagens em PDFs
|
|
74
|
+
option :fuzz, type: :numeric, default: 29, desc: 'fuzz trim jpg N-1, escolhe menor -> scanned pdf'
|
|
75
|
+
option :quality, type: :numeric, default: 15, desc: 'compress jpg N% -> scanned pdf (less=low quality)'
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
option :sound,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
option :amount, type: :numeric, default: 0.00001,
|
|
86
|
-
desc: 'qtd ruido a ser removido'
|
|
87
|
-
option :rate, type: :numeric, default: 16,
|
|
88
|
-
desc: 'sample rate - radio-16k, CD-44.1k, PC-48k, pro-96k'
|
|
77
|
+
# opcoes para compressao de audio
|
|
78
|
+
option :threshold, type: :numeric, default: 9, desc: 'limiar maximo para silencio, 0% = silencio puro'
|
|
79
|
+
option :sound, type: :numeric, default: 1, desc: 'segundos de som para terminar silencio'
|
|
80
|
+
option :amount, type: :numeric, default: 0.00001, desc: 'qtd ruido a ser removido'
|
|
81
|
+
option :rate, type: :numeric, default: 16, desc: 'sample rate - radio-16k, CD-44.1k, PC-48k, pro-96k'
|
|
89
82
|
# arquiva pasta de documentos c118
|
|
90
83
|
#
|
|
91
84
|
# @param [String] pasta contem os documentos para arquivar
|
|
@@ -0,0 +1,60 @@
|
|
|
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').values.flatten[0]
|
|
26
|
+
i = folhas.get_spreadsheet_values(s, 'bal!R2:R').values.flatten.join(',')
|
|
27
|
+
puts 'processamento bigquery feito para ano ' + a + ": [del_bal,del_hise,ins_bal,ins_hise] #{sql_big(a, i)}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# executa comandos DML para processa no bigquery
|
|
31
|
+
#
|
|
32
|
+
# @return [Array<Integer>] numero linhas afetadas pelos DMLs
|
|
33
|
+
def sql_big(ano, lst)
|
|
34
|
+
[dml('delete FROM arquivo.bal WHERE ano=' + ano),
|
|
35
|
+
dml('delete FROM arquivo.hise WHERE ano=' + ano),
|
|
36
|
+
dml("INSERT arquivo.bal (#{col_bal}) VALUES" + lst),
|
|
37
|
+
dml("INSERT arquivo.hise(#{col_hise}) select * from arquivo.vhe where ano=" + ano)]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return [String] colunas da tabela bal no bigquery
|
|
41
|
+
def col_bal
|
|
42
|
+
'data,entidade,documento,descricao,valor,tag,dr,banco,conta,ano,id4,dref,daa,paga,desb'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @return [String] colunas da tabela hise no bigquery
|
|
46
|
+
def col_hise
|
|
47
|
+
'ano,dr,tag,descricao,valor'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# executa comando DML (Data Manipulation Language) no bigquery
|
|
51
|
+
#
|
|
52
|
+
# @return [Integer] numero linhas afetadas pelo DML
|
|
53
|
+
def dml(sql)
|
|
54
|
+
job = big.query_job(sql)
|
|
55
|
+
job.wait_until_done!
|
|
56
|
+
puts job.error if job.failed?
|
|
57
|
+
job.num_dml_affected_rows
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
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,18 +62,6 @@ module Arquivo
|
|
|
67
62
|
processa_items
|
|
68
63
|
end
|
|
69
64
|
|
|
70
|
-
def processa_big
|
|
71
|
-
puts contem
|
|
72
|
-
# This uses Application Default Credentials to authenticate.
|
|
73
|
-
# @see https://cloud.google.com/bigquery/docs/authentication/getting-started
|
|
74
|
-
bigquery = Google::Cloud::Bigquery.new
|
|
75
|
-
|
|
76
|
-
r = bigquery.query 'select * from arquivo.bal order by 1 desc limit 10'
|
|
77
|
-
r.each do |row|
|
|
78
|
-
puts "#{row[:data]}: #{row[:documento]}"
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
65
|
# @return [String] proximo item dentro da pasta
|
|
83
66
|
def next_item
|
|
84
67
|
@item = items.next
|
|
@@ -86,49 +69,20 @@ module Arquivo
|
|
|
86
69
|
@item = nil
|
|
87
70
|
end
|
|
88
71
|
|
|
89
|
-
# @!group dados
|
|
90
|
-
# @return [Hash] dados oficiais para
|
|
72
|
+
# @!group dados folhas-calculo c118
|
|
73
|
+
# @return [Hash] dados oficiais para classificacao de faturas e recibos
|
|
91
74
|
def obtem_dados
|
|
92
75
|
@dados = {}
|
|
93
76
|
# somente faturas e recibos necessitam reclassificacao
|
|
94
77
|
return unless %i[fft frc].include?(contem)
|
|
95
78
|
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
@dados =
|
|
99
|
-
|
|
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+/] }
|
|
100
84
|
rescue StandardError
|
|
101
85
|
@dados = {}
|
|
102
86
|
end
|
|
103
|
-
|
|
104
|
-
# assegura credenciais validas, obtidas dum ficheiro de credencias
|
|
105
|
-
#
|
|
106
|
-
# @return [Google::Apis::SheetsV4::SheetsService] c118 sheets_v4
|
|
107
|
-
def c118_sheets
|
|
108
|
-
p = '/home/c118/.'
|
|
109
|
-
# file obtido console.cloud.google.com/apis OAuth 2.0 client IDs
|
|
110
|
-
i = Google::Auth::ClientId.from_file("#{p}sheets.json")
|
|
111
|
-
s = Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
|
|
112
|
-
# file criado aquando new_credentials is executed
|
|
113
|
-
f = Google::Auth::Stores::FileTokenStore.new(file: "#{p}sheets.yaml")
|
|
114
|
-
z = Google::Auth::UserAuthorizer.new(i, s, f)
|
|
115
|
-
|
|
116
|
-
sheets = Google::Apis::SheetsV4::SheetsService.new
|
|
117
|
-
sheets.client_options.application_name = 'c118-arquivo'
|
|
118
|
-
sheets.authorization = z.get_credentials('default') ||
|
|
119
|
-
new_credentials(z, 'urn:ietf:wg:oauth:2.0:oob')
|
|
120
|
-
sheets
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# inicializar OAuth2 authorization abrindo URL e copiando novo codigo
|
|
124
|
-
#
|
|
125
|
-
# @return [Google::Auth::UserAuthorizer] OAuth2 credentials
|
|
126
|
-
def new_credentials(aut, oob)
|
|
127
|
-
puts 'Open URL and copy code after authorization, in <codigo-aqui>',
|
|
128
|
-
aut.get_authorization_url(base_url: oob)
|
|
129
|
-
aut.get_and_store_credentials_from_code(user_id: 'default',
|
|
130
|
-
code: '<codigo-aqui>',
|
|
131
|
-
base_url: oob)
|
|
132
|
-
end
|
|
133
87
|
end
|
|
134
88
|
end
|
data/lib/arquivo/extrato.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'pdf-reader'
|
|
|
4
4
|
|
|
5
5
|
module Arquivo
|
|
6
6
|
# permite processar documentos PDF
|
|
7
|
-
class C118pdf
|
|
7
|
+
class C118pdf
|
|
8
8
|
# @return [String] nome do documento
|
|
9
9
|
attr_reader :file
|
|
10
10
|
# @return [String] extensao do documento
|
|
@@ -128,21 +128,5 @@ module Arquivo
|
|
|
128
128
|
puts "#{nome}-extrato"
|
|
129
129
|
nome_extrato
|
|
130
130
|
end
|
|
131
|
-
|
|
132
|
-
# cria PDF do dashboard
|
|
133
|
-
def faz_dashboard
|
|
134
|
-
c = 'gs -sDEVICE=pdfwrite ' \
|
|
135
|
-
'-dNOPAUSE -dBATCH -dQUIET -dPDFSETTINGS=/printer ' \
|
|
136
|
-
'-sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dAutoRotatePages=/All'
|
|
137
|
-
system "#{c} -sOutputFile=#{base}-a4.pdf \"#{file}\" #{O2}"
|
|
138
|
-
puts "#{base}-a4"
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# segmenta PDF pelas suas paginas
|
|
142
|
-
def split
|
|
143
|
-
system "pdftk #{file} burst output #{base}/pg%04d-#{base}.pdf;" \
|
|
144
|
-
"rm -f #{base}/*.txt"
|
|
145
|
-
puts "#{base}-split"
|
|
146
|
-
end
|
|
147
131
|
end
|
|
148
132
|
end
|
data/lib/arquivo/mp3.rb
CHANGED
|
@@ -17,8 +17,7 @@ module Arquivo
|
|
|
17
17
|
# @param [String] mp3 MP3 c118
|
|
18
18
|
# @param [Hash] opt parametrizar MINUTA
|
|
19
19
|
# @option opt [Numeric] :amount (0.00001) qtd ruido a ser removido,
|
|
20
|
-
# @option opt [Numeric] :rate (16) sample rate - radio-16k, CD-44.1k,
|
|
21
|
-
# PC-48k, pro-96k
|
|
20
|
+
# @option opt [Numeric] :rate (16) sample rate - radio-16k, CD-44.1k, PC-48k, pro-96k
|
|
22
21
|
# @return [C118mp3] MP3 c118
|
|
23
22
|
def initialize(mp3, opt)
|
|
24
23
|
@file = mp3
|
data/lib/arquivo/noise.rb
CHANGED
|
@@ -31,28 +31,21 @@ module Arquivo
|
|
|
31
31
|
|
|
32
32
|
# @param pasta (see CLI#dir)
|
|
33
33
|
# @param [Hash] opt parametrizar JPG, MINUTA
|
|
34
|
-
# @option opt [Numeric] :fuzz (29) trim jpg N-1, escolhe menor ->
|
|
35
|
-
#
|
|
36
|
-
# @option opt [Numeric] :
|
|
37
|
-
# (less=low quality)
|
|
38
|
-
# @option opt [Numeric] :threshold (9) limiar maximo para silencio,
|
|
39
|
-
# 0% = silencio puro
|
|
34
|
+
# @option opt [Numeric] :fuzz (29) trim jpg N-1, escolhe menor -> scanned pdf
|
|
35
|
+
# @option opt [Numeric] :quality (15) compress jpg N% -> scanned pdf (less=low quality)
|
|
36
|
+
# @option opt [Numeric] :threshold (9) limiar maximo para silencio, 0% = silencio puro
|
|
40
37
|
# @option opt [Numeric] :sound (1) segundos de som para terminar silencio
|
|
41
38
|
# @option opt [Numeric] :amount (0.00001) qtd ruido a ser removido,
|
|
42
|
-
# @option opt [Numeric] :rate (16) sample rate - radio-16k, CD-44.1k,
|
|
43
|
-
# PC-48k, pro-96k
|
|
39
|
+
# @option opt [Numeric] :rate (16) sample rate - radio-16k, CD-44.1k, PC-48k, pro-96k
|
|
44
40
|
# @return [C118dir] pasta de documentos c118
|
|
45
41
|
def initialize(dir, opt)
|
|
46
42
|
c = Dir.glob(File.join(dir, '*'))
|
|
47
|
-
puts c
|
|
48
43
|
@local = dir
|
|
49
|
-
puts @local
|
|
50
44
|
@items = c.each
|
|
51
45
|
@nome = File.basename(dir, File.extname(dir)) + '-' +
|
|
52
46
|
Date.today.strftime('%Y%m%d')
|
|
53
47
|
@opcoes = opt
|
|
54
48
|
@contem = obtem_conteudo(c)
|
|
55
|
-
puts @contem
|
|
56
49
|
end
|
|
57
50
|
|
|
58
51
|
# Agrupa conteudo duma pasta segundo tipos de documentos validos
|
data/lib/arquivo/pdf.rb
CHANGED
|
@@ -7,7 +7,7 @@ I18n.config.available_locales = :pt
|
|
|
7
7
|
|
|
8
8
|
module Arquivo
|
|
9
9
|
# permite processar documentos PDF
|
|
10
|
-
class C118pdf
|
|
10
|
+
class C118pdf
|
|
11
11
|
# @!group processamento
|
|
12
12
|
# processa pdf para arquivo
|
|
13
13
|
#
|
|
@@ -143,5 +143,20 @@ module Arquivo
|
|
|
143
143
|
"pdftk tmp/zip/#{base}.pdf " \
|
|
144
144
|
"stamp tmp/stamp-#{id}.pdf output #{o} #{O2}"
|
|
145
145
|
end
|
|
146
|
+
|
|
147
|
+
# cria PDF do dashboard
|
|
148
|
+
def faz_dashboard
|
|
149
|
+
c = 'gs -sDEVICE=pdfwrite ' \
|
|
150
|
+
'-dNOPAUSE -dBATCH -dQUIET -dPDFSETTINGS=/printer ' \
|
|
151
|
+
'-sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dAutoRotatePages=/All'
|
|
152
|
+
system "#{c} -sOutputFile=#{base}-a4.pdf \"#{file}\" #{O2}"
|
|
153
|
+
puts "#{base}-a4"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# segmenta PDF pelas suas paginas
|
|
157
|
+
def split
|
|
158
|
+
system "pdftk #{file} burst output #{base}/pg%04d-#{base}.pdf;rm -f #{base}/*.txt"
|
|
159
|
+
puts "#{base}-split"
|
|
160
|
+
end
|
|
146
161
|
end
|
|
147
162
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
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') || new_credentials(z, 'urn:ietf:wg:oauth:2.0:oob')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# inicializar OAuth2 authorization abrindo URL e copiando novo codigo
|
|
35
|
+
#
|
|
36
|
+
# @return [Google::Auth::UserAuthorizer] OAuth2 credentials
|
|
37
|
+
def new_credentials(aut, oob)
|
|
38
|
+
puts 'Open URL and copy code after authorization, in <codigo-aqui>', aut.get_authorization_url(base_url: oob)
|
|
39
|
+
aut.get_and_store_credentials_from_code(user_id: 'default', code: '<codigo-aqui>', base_url: oob)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/arquivo/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: arquivo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2
|
|
4
|
+
version: 0.3.2
|
|
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:
|
|
11
|
+
date: 2021-06-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -42,30 +42,30 @@ dependencies:
|
|
|
42
42
|
name: fastimage
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '0'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: google-api-client
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0
|
|
61
|
+
version: '0'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0
|
|
68
|
+
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: google-cloud-bigquery
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,48 +80,62 @@ 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
|
|
86
100
|
requirements:
|
|
87
|
-
- - "
|
|
101
|
+
- - ">="
|
|
88
102
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
103
|
+
version: '0'
|
|
90
104
|
type: :runtime
|
|
91
105
|
prerelease: false
|
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
107
|
requirements:
|
|
94
|
-
- - "
|
|
108
|
+
- - ">="
|
|
95
109
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
110
|
+
version: '0'
|
|
97
111
|
- !ruby/object:Gem::Dependency
|
|
98
112
|
name: thor
|
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
|
100
114
|
requirements:
|
|
101
|
-
- - "
|
|
115
|
+
- - ">="
|
|
102
116
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0
|
|
117
|
+
version: '0'
|
|
104
118
|
type: :runtime
|
|
105
119
|
prerelease: false
|
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
121
|
requirements:
|
|
108
|
-
- - "
|
|
122
|
+
- - ">="
|
|
109
123
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0
|
|
124
|
+
version: '0'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
126
|
name: yard
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
114
128
|
requirements:
|
|
115
|
-
- - "
|
|
129
|
+
- - ">="
|
|
116
130
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: '0
|
|
131
|
+
version: '0'
|
|
118
132
|
type: :runtime
|
|
119
133
|
prerelease: false
|
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
135
|
requirements:
|
|
122
|
-
- - "
|
|
136
|
+
- - ">="
|
|
123
137
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '0
|
|
138
|
+
version: '0'
|
|
125
139
|
description: Processa documentos do condominio ph1341c118 para arquivo. Pode tambem
|
|
126
140
|
segmentar PDFs e MINUTAS. Tendo os documentos em pastas separadas, pode ainda criar
|
|
127
141
|
arquivos apropriados.
|
|
@@ -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:
|
|
@@ -171,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
171
187
|
- !ruby/object:Gem::Version
|
|
172
188
|
version: '0'
|
|
173
189
|
requirements: []
|
|
174
|
-
rubygems_version: 3.
|
|
190
|
+
rubygems_version: 3.2.19
|
|
175
191
|
signing_key:
|
|
176
192
|
specification_version: 4
|
|
177
193
|
summary: Processa documentos do condominio ph1341c118 para arquivo.
|