jetel 0.0.7 → 0.0.8
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 +3 -3
- data/Rakefile +4 -1
- data/jetel.gemspec +1 -1
- data/lib/jetel/cli/cmd/modules_cmd.rb +14 -6
- data/lib/jetel/downloader/backends/aria.rb +3 -1
- data/lib/jetel/loaders/pg/pg.rb +5 -3
- data/lib/jetel/loaders/pg/sql/copy.sql.erb +6 -1
- data/lib/jetel/modules/geolite/geolite.rb +50 -0
- data/lib/jetel/modules/iso3166/iso3166.rb +1 -15
- data/lib/jetel/modules/module.rb +21 -1
- data/lib/jetel/modules/nga/nga.rb +1 -15
- data/lib/jetel/modules/wifileaks/wifileaks.rb +78 -0
- data/lib/jetel/version.rb +1 -1
- metadata +5 -4
- data/data/.gitkeepme +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f223ffcd2b8d33c2fe12cfb2a4f20472dadc5ae9
|
4
|
+
data.tar.gz: ac9d7188dbfce5b31be2a0adfa7c3327645a5f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa892d6a6dfcfd26e19131f78cda6db99d625eff6f4cafe80f0035af387f4348b4497191a6d91a4b2e3b0b74d1534ce3113a8de5cb27fd1c88b35a8ac2da1f0
|
7
|
+
data.tar.gz: 9f51835cd7ffab18ac93d975ce6c017814026ec392a3057a93968fbf1941f0444f4dc42e4375476e8569f737808dadc16c3f3fbf1e0c8f2956f28bbbefae2a08
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jetel (0.0.
|
4
|
+
jetel (0.0.7)
|
5
5
|
activesupport
|
6
|
-
csv2psql
|
6
|
+
csv2psql (~> 0.0.19)
|
7
7
|
gli
|
8
8
|
i18n
|
9
9
|
json_pure
|
@@ -18,7 +18,7 @@ PATH
|
|
18
18
|
PATH
|
19
19
|
remote: /Users/tomaskorcak/dev/csv2psql
|
20
20
|
specs:
|
21
|
-
csv2psql (0.0.
|
21
|
+
csv2psql (0.0.19)
|
22
22
|
gli (~> 2.13, >= 2.13.2)
|
23
23
|
json_pure (~> 1.8, >= 1.8.3)
|
24
24
|
lru (~> 0.1, >= 0.1.0)
|
data/Rakefile
CHANGED
data/jetel.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.add_dependency 'activesupport'
|
23
|
-
spec.add_dependency 'csv2psql', '~> 0.0.
|
23
|
+
spec.add_dependency 'csv2psql', '~> 0.0.19'
|
24
24
|
spec.add_dependency 'gli'
|
25
25
|
spec.add_dependency 'i18n'
|
26
26
|
spec.add_dependency 'json_pure'
|
@@ -11,12 +11,20 @@ MODULES_ACTIONS = {
|
|
11
11
|
extract: nil,
|
12
12
|
transform: nil,
|
13
13
|
load: {
|
14
|
-
params: [
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
params: [
|
15
|
+
{
|
16
|
+
desc: 'Column type',
|
17
|
+
default_value: nil,
|
18
|
+
arg_name: 'column-name=column-type',
|
19
|
+
flag: [:column_type]
|
20
|
+
},
|
21
|
+
{
|
22
|
+
desc: 'Num Lines to analyze',
|
23
|
+
default_value: 1000,
|
24
|
+
arg_name: 'num',
|
25
|
+
flag: [:analyze_num_rows]
|
26
|
+
}
|
27
|
+
]
|
20
28
|
}
|
21
29
|
}
|
22
30
|
|
@@ -14,7 +14,9 @@ module Jetel
|
|
14
14
|
|
15
15
|
opts = BaseDownloader::OPTS_DOWNLOAD.merge(opts)
|
16
16
|
|
17
|
-
|
17
|
+
filename = opts[:filename] || url.split('/').last
|
18
|
+
|
19
|
+
cmd = "aria2c -j 4 -t #{opts[:timeout]} -d \"#{opts[:dir]}\" -o \"#{filename}\" #{url}"
|
18
20
|
puts(cmd)
|
19
21
|
|
20
22
|
PTY.spawn(cmd) do |stdout, stdin, pid|
|
data/lib/jetel/loaders/pg/pg.rb
CHANGED
@@ -40,9 +40,10 @@ module Jetel
|
|
40
40
|
super
|
41
41
|
|
42
42
|
convert_opts = {
|
43
|
-
:l =>
|
43
|
+
:l => opts['analyze_num_rows'] && opts['analyze_num_rows'].to_i,
|
44
44
|
:skip => 0,
|
45
|
-
:header => true
|
45
|
+
:header => true,
|
46
|
+
:delimiter => opts[:delimiter]
|
46
47
|
}
|
47
48
|
|
48
49
|
schema_list = Csv2Psql::Convert.generate_schema([file], convert_opts)
|
@@ -80,7 +81,8 @@ module Jetel
|
|
80
81
|
:columns => schema[:columns],
|
81
82
|
:source => source,
|
82
83
|
:module => modul,
|
83
|
-
:file => File.absolute_path(modul.transformed_file(source, opts))
|
84
|
+
:file => File.absolute_path(modul.transformed_file(source, opts)),
|
85
|
+
:delimiter => opts[:delimiter]
|
84
86
|
}
|
85
87
|
}
|
86
88
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'pmap'
|
4
|
+
|
5
|
+
require_relative '../../config/config'
|
6
|
+
require_relative '../../modules/module'
|
7
|
+
|
8
|
+
module Jetel
|
9
|
+
module Modules
|
10
|
+
class Geolite < Module
|
11
|
+
class << self
|
12
|
+
def sources
|
13
|
+
[
|
14
|
+
{
|
15
|
+
name: 'geolite',
|
16
|
+
# filename_downloaded: 'SFPD_Incidents_-_from_1_January_2003.csv',
|
17
|
+
filename_extracted: 'GeoLite2-City-Blocks-IPv4.csv',
|
18
|
+
filename_transformed: 'GeoLite2-City-Blocks-IPv4.csv',
|
19
|
+
url: 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip'
|
20
|
+
}
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def download(global_options, options, args)
|
26
|
+
self.class.sources.pmap do |source|
|
27
|
+
download_source(source, global_options.merge(options))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract(global_options, options, args)
|
32
|
+
self.class.sources.pmap do |source|
|
33
|
+
unzip(source, global_options.merge(options))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def transform(global_options, options, args)
|
38
|
+
self.class.sources.pmap do |source|
|
39
|
+
extracted_file = extracted_file(source, global_options.merge(options))
|
40
|
+
dest_dir = transform_dir(source, global_options.merge(options))
|
41
|
+
|
42
|
+
puts "Transforming #{extracted_file}"
|
43
|
+
|
44
|
+
FileUtils.mkdir_p(dest_dir)
|
45
|
+
FileUtils.cp(extracted_file, dest_dir)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -31,21 +31,7 @@ module Jetel
|
|
31
31
|
|
32
32
|
def extract(global_options, options, args)
|
33
33
|
self.class.sources.pmap do |source|
|
34
|
-
|
35
|
-
dest_dir = extract_dir(source, global_options.merge(options))
|
36
|
-
|
37
|
-
FileUtils.mkdir_p(dest_dir)
|
38
|
-
|
39
|
-
Zip::ZipFile.open(downloaded_file) do |zip_file|
|
40
|
-
# Handle entries one by one
|
41
|
-
zip_file.each do |entry|
|
42
|
-
# Extract to file/directory/symlink
|
43
|
-
puts "Extracting #{entry.name}"
|
44
|
-
dest_file = File.join(dest_dir, entry.name.split('/').last)
|
45
|
-
FileUtils.rm_rf(dest_file)
|
46
|
-
entry.extract(dest_file)
|
47
|
-
end
|
48
|
-
end
|
34
|
+
unzip(source, global_options.merge(options))
|
49
35
|
end
|
50
36
|
end
|
51
37
|
|
data/lib/jetel/modules/module.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'zip'
|
4
|
+
|
3
5
|
require_relative '../downloader/downloader'
|
4
6
|
require_relative '../helpers/helpers'
|
5
7
|
|
@@ -45,7 +47,7 @@ module Jetel
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def download_source(source, opts)
|
48
|
-
downloader.download(source[:url], {:dir => download_dir(source, opts)})
|
50
|
+
downloader.download(source[:url], {:dir => download_dir(source, opts), :filename => source[:filename_downloaded]})
|
49
51
|
end
|
50
52
|
|
51
53
|
def target_dir(source, opts, *path)
|
@@ -95,6 +97,24 @@ module Jetel
|
|
95
97
|
loader.load(self, source, transformed_file, opts)
|
96
98
|
end
|
97
99
|
end
|
100
|
+
|
101
|
+
def unzip(source, options = {})
|
102
|
+
downloaded_file = downloaded_file(source, options)
|
103
|
+
dest_dir = extract_dir(source, options)
|
104
|
+
|
105
|
+
FileUtils.mkdir_p(dest_dir)
|
106
|
+
|
107
|
+
Zip::ZipFile.open(downloaded_file) do |zip_file|
|
108
|
+
# Handle entries one by one
|
109
|
+
zip_file.each do |entry|
|
110
|
+
# Extract to file/directory/symlink
|
111
|
+
puts "Extracting #{entry.name}"
|
112
|
+
dest_file = File.join(dest_dir, entry.name.split('/').last)
|
113
|
+
FileUtils.rm_rf(dest_file)
|
114
|
+
entry.extract(dest_file)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
98
118
|
end
|
99
119
|
end
|
100
120
|
end
|
@@ -1050,21 +1050,7 @@ module Jetel
|
|
1050
1050
|
|
1051
1051
|
def extract(global_options, options, args)
|
1052
1052
|
self.class.sources.pmap do |source|
|
1053
|
-
|
1054
|
-
dest_dir = extract_dir(source, global_options.merge(options))
|
1055
|
-
|
1056
|
-
FileUtils.mkdir_p(dest_dir)
|
1057
|
-
|
1058
|
-
Zip::ZipFile.open(downloaded_file) do |zip_file|
|
1059
|
-
# Handle entries one by one
|
1060
|
-
zip_file.each do |entry|
|
1061
|
-
# Extract to file/directory/symlink
|
1062
|
-
puts "Extracting #{entry.name}"
|
1063
|
-
dest_file = File.join(dest_dir, entry.name.split('/').last)
|
1064
|
-
FileUtils.rm_rf(dest_file)
|
1065
|
-
entry.extract(dest_file)
|
1066
|
-
end
|
1067
|
-
end
|
1053
|
+
unzip(source, global_options.merge(options))
|
1068
1054
|
end
|
1069
1055
|
end
|
1070
1056
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'pmap'
|
4
|
+
|
5
|
+
require_relative '../../config/config'
|
6
|
+
require_relative '../../modules/module'
|
7
|
+
|
8
|
+
module Jetel
|
9
|
+
module Modules
|
10
|
+
class Wifileaks < Module
|
11
|
+
class << self
|
12
|
+
def sources
|
13
|
+
[
|
14
|
+
{
|
15
|
+
name: 'wifileaks',
|
16
|
+
url: 'http://download.wifileaks.cz/data/wifileaks_150709.tsv'
|
17
|
+
}
|
18
|
+
]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def download(global_options, options, args)
|
23
|
+
self.class.sources.pmap do |source|
|
24
|
+
download_source(source, global_options.merge(options))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract(global_options, options, args)
|
29
|
+
self.class.sources.pmap do |source|
|
30
|
+
downloaded_file = downloaded_file(source, global_options.merge(options))
|
31
|
+
dest_dir = extract_dir(source, global_options.merge(options))
|
32
|
+
|
33
|
+
puts "Extracting #{downloaded_file}"
|
34
|
+
|
35
|
+
FileUtils.mkdir_p(dest_dir)
|
36
|
+
FileUtils.cp(downloaded_file, dest_dir)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def transform(global_options, options, args)
|
41
|
+
self.class.sources.pmap do |source|
|
42
|
+
opts = global_options.merge(options)
|
43
|
+
|
44
|
+
extracted_file = extracted_file(source, opts)
|
45
|
+
transformed_file = transformed_file(source, opts)
|
46
|
+
|
47
|
+
puts "Transforming #{extracted_file}"
|
48
|
+
|
49
|
+
headers = %w(
|
50
|
+
MAC
|
51
|
+
SSID
|
52
|
+
security
|
53
|
+
latitude
|
54
|
+
longitude
|
55
|
+
altitude
|
56
|
+
updated_at
|
57
|
+
)
|
58
|
+
|
59
|
+
File.open(extracted_file, 'r') do |file_in|
|
60
|
+
File.open(transformed_file, 'w') do |file_out|
|
61
|
+
file_out.puts(headers.join("\t"))
|
62
|
+
file_in.each do |line|
|
63
|
+
next if line == "\n"
|
64
|
+
file_out.puts(line.chomp)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def load(global_options, options, args)
|
72
|
+
res = super(global_options, options.merge({:delimiter => "\t"}), args)
|
73
|
+
res
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/jetel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jetel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Korcak
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
33
|
+
version: 0.0.19
|
34
34
|
type: :runtime
|
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: 0.0.
|
40
|
+
version: 0.0.19
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: gli
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,7 +281,6 @@ files:
|
|
281
281
|
- README.md
|
282
282
|
- Rakefile
|
283
283
|
- bin/jetel
|
284
|
-
- data/.gitkeepme
|
285
284
|
- docks/postgresql/pull.sh
|
286
285
|
- docks/postgresql/run.sh
|
287
286
|
- jetel.gemspec
|
@@ -312,12 +311,14 @@ files:
|
|
312
311
|
- lib/jetel/loaders/pg/sql/header.sql.erb
|
313
312
|
- lib/jetel/loaders/pg/sql/schema.sql.erb
|
314
313
|
- lib/jetel/loaders/pg/sql/truncate_table.sql.erb
|
314
|
+
- lib/jetel/modules/geolite/geolite.rb
|
315
315
|
- lib/jetel/modules/ip/ip.rb
|
316
316
|
- lib/jetel/modules/iso3166/iso3166.rb
|
317
317
|
- lib/jetel/modules/module.rb
|
318
318
|
- lib/jetel/modules/modules.rb
|
319
319
|
- lib/jetel/modules/nga/nga.rb
|
320
320
|
- lib/jetel/modules/sfpd/sfpd.rb
|
321
|
+
- lib/jetel/modules/wifileaks/wifileaks.rb
|
321
322
|
- lib/jetel/version.rb
|
322
323
|
- test/spec_helper.rb
|
323
324
|
homepage: https://github.com/korczis/jetel
|
data/data/.gitkeepme
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# KEEP ME, PLEASE !!!
|