chronicle-etl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/chronicle-etl.gemspec +48 -0
- data/exe/chronicle-etl +5 -0
- data/lib/chronicle/etl.rb +5 -0
- data/lib/chronicle/etl/cli.rb +38 -0
- data/lib/chronicle/etl/extractors/csv.rb +44 -0
- data/lib/chronicle/etl/extractors/extractor.rb +20 -0
- data/lib/chronicle/etl/extractors/stdin.rb +13 -0
- data/lib/chronicle/etl/loaders/csv.rb +31 -0
- data/lib/chronicle/etl/loaders/loader.rb +25 -0
- data/lib/chronicle/etl/loaders/stdout.rb +13 -0
- data/lib/chronicle/etl/loaders/table.rb +22 -0
- data/lib/chronicle/etl/runner.rb +37 -0
- data/lib/chronicle/etl/transformers/json.rb +13 -0
- data/lib/chronicle/etl/transformers/null.rb +11 -0
- data/lib/chronicle/etl/transformers/transformer.rb +18 -0
- data/lib/chronicle/etl/utils/progress_bar_wrapper.rb +43 -0
- data/lib/chronicle/etl/version.rb +5 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8dcc1235575087fdd8a973342aceee215912cfcc84ef23efbb7a7b3cc408250d
|
4
|
+
data.tar.gz: 1c548fec675e6f4f219a73bf8ec707b00ba38817a1cb54b6d190408fa1676c42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4afc6c280c8ab8c8d49f8b50beccab0084c6f75f1903f4d3e6d700b4e9f74ea4914d1f43024260db5f85c8e734f14ed1e1b1382f4d3fe0579c23ac336e5e7067
|
7
|
+
data.tar.gz: 0d7b4c9cb43c0d3ccf56b4315ae46d73e29efebb53bdf3e29d151b68dadbc4b648582dc3d898d695b4aaf07afa90f711324827e5a6c1d98de451b5a318d87f86
|
data/.gitignore
ADDED
data/.rspec
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 andrew@hyfen.net. 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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
chronicle-etl (0.1.0)
|
5
|
+
colorize (~> 0.8.1)
|
6
|
+
ruby-progressbar (~> 1.10)
|
7
|
+
table_print
|
8
|
+
thor (~> 0.20)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
byebug (11.1.3)
|
14
|
+
coderay (1.1.3)
|
15
|
+
colorize (0.8.1)
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
method_source (1.0.0)
|
18
|
+
pry (0.13.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
pry-byebug (3.9.0)
|
22
|
+
byebug (~> 11.0)
|
23
|
+
pry (~> 0.13.0)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.9.0)
|
26
|
+
rspec-core (~> 3.9.0)
|
27
|
+
rspec-expectations (~> 3.9.0)
|
28
|
+
rspec-mocks (~> 3.9.0)
|
29
|
+
rspec-core (3.9.2)
|
30
|
+
rspec-support (~> 3.9.3)
|
31
|
+
rspec-expectations (3.9.2)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-mocks (3.9.1)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-support (3.9.3)
|
38
|
+
ruby-progressbar (1.10.1)
|
39
|
+
table_print (1.5.7)
|
40
|
+
thor (0.20.3)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 1.17)
|
47
|
+
chronicle-etl!
|
48
|
+
pry-byebug (~> 3.9)
|
49
|
+
rake (~> 10.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Andrew Louis
|
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,65 @@
|
|
1
|
+
# Chronicle::Etl
|
2
|
+
|
3
|
+
Chronicle ETL is a utility tool for manipulating personal data. You can extract it from a variety of source, transform it, and load it to different APIs or file formats.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
$ gem install chronicle-etl
|
9
|
+
```
|
10
|
+
|
11
|
+
## Examples
|
12
|
+
|
13
|
+
After installing the gem, `chronicle-etl` is available to run in your shell.
|
14
|
+
|
15
|
+
```
|
16
|
+
chronicle-etl --extractor csv --extractor-opts filename:test.csv --loader table
|
17
|
+
cat test.csv | chronicle-etl --extractor csv --loader table
|
18
|
+
```
|
19
|
+
|
20
|
+
## Full usage
|
21
|
+
|
22
|
+
```
|
23
|
+
Commands:
|
24
|
+
chronicle-etl help [COMMAND] # Describe available commands or one specific command
|
25
|
+
chronicle-etl job # Runs an ETL job
|
26
|
+
```
|
27
|
+
|
28
|
+
### Job options
|
29
|
+
|
30
|
+
```
|
31
|
+
Usage:
|
32
|
+
chronicle-etl job
|
33
|
+
|
34
|
+
Options:
|
35
|
+
-e, [--extractor=extractor-name] # Extractor class (available: stdin, csv, file)
|
36
|
+
# Default: stdin
|
37
|
+
[--extractor-opts=key:value] # Extractor options
|
38
|
+
-t, [--transformer=transformer-name] # Transformer class (available: null)
|
39
|
+
# Default: null
|
40
|
+
[--transformer-opts=key:value] # Transformer options
|
41
|
+
-l, [--loader=loader-name] # Loader class (available: stdout, csv, table)
|
42
|
+
# Default: stdout
|
43
|
+
[--loader-opts=key:value] # Loader options
|
44
|
+
-j, [--job=JOB] # Job configuration file
|
45
|
+
|
46
|
+
Runs an ETL job
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chronicle-app/chronicle-etl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
62
|
+
|
63
|
+
## Code of Conduct
|
64
|
+
|
65
|
+
Everyone interacting in the Chronicle::Etl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/chronicle-app/chronicle-etl/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 "chronicle/etl"
|
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
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "chronicle/etl/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chronicle-etl"
|
8
|
+
spec.version = Chronicle::Etl::VERSION
|
9
|
+
spec.authors = ["Andrew Louis"]
|
10
|
+
spec.email = ["andrew@hyfen.net"]
|
11
|
+
|
12
|
+
spec.summary = "ETL tool for personal data"
|
13
|
+
spec.description = "Chronicle-ETL allows you to extract personal data from a variety of services, transformer it, and load it."
|
14
|
+
spec.homepage = "https://github.com/chronicle-app"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/chronicle-app/chronicle-etl"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/chronicle-app/chronicle-etl"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_dependency "thor", "~> 0.20"
|
40
|
+
spec.add_dependency "colorize", "~> 0.8.1"
|
41
|
+
spec.add_dependency "table_print"
|
42
|
+
spec.add_dependency "ruby-progressbar", "~> 1.10"
|
43
|
+
|
44
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
45
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
46
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
47
|
+
spec.add_development_dependency "pry-byebug", "~> 3.9"
|
48
|
+
end
|
data/exe/chronicle-etl
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'chronicle/etl'
|
3
|
+
|
4
|
+
module Chronicle
|
5
|
+
module Etl
|
6
|
+
class CLI < Thor
|
7
|
+
default_task :job
|
8
|
+
|
9
|
+
desc 'job', 'Runs an ETL job'
|
10
|
+
method_option :extractor, aliases: '-e', desc: 'Extractor class (available: stdin, csv, file)', default: 'stdin', banner: 'extractor-name'
|
11
|
+
method_option :'extractor-opts', desc: 'Extractor options', type: :hash, default: {}
|
12
|
+
method_option :transformer, aliases: '-t', desc: 'Transformer class (available: null)', default: 'null', banner: 'transformer-name'
|
13
|
+
method_option :'transformer-opts', desc: 'Transformer options', type: :hash, default: {}
|
14
|
+
method_option :loader, aliases: '-l', desc: 'Loader class (available: stdout, csv, table)', default: 'stdout', banner: 'loader-name'
|
15
|
+
method_option :'loader-opts', desc: 'Loader options', type: :hash, default: {}
|
16
|
+
method_option :job, aliases: '-j', desc: 'Job configuration file'
|
17
|
+
def job
|
18
|
+
runner_options = {
|
19
|
+
extractor: {
|
20
|
+
name: options[:extractor],
|
21
|
+
options: options[:'extractor-opts']
|
22
|
+
},
|
23
|
+
transformer: {
|
24
|
+
name: options[:transformer],
|
25
|
+
options: options[:'transformer-opts']
|
26
|
+
},
|
27
|
+
loader: {
|
28
|
+
name: options[:loader],
|
29
|
+
options: options[:'loader-opts']
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
runner = Runner.new(runner_options)
|
34
|
+
runner.run!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'pry-byebug'
|
3
|
+
|
4
|
+
class Chronicle::Etl::Extractors::Csv < Chronicle::Etl::Extractors::Extractor
|
5
|
+
DEFAULT_OPTIONS = {
|
6
|
+
headers: true,
|
7
|
+
filename: $stdin
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
super(DEFAULT_OPTIONS.merge(options))
|
12
|
+
end
|
13
|
+
|
14
|
+
def extract
|
15
|
+
csv = initialize_csv
|
16
|
+
csv.each do |row|
|
17
|
+
result = row.to_h
|
18
|
+
yield result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def results_count
|
23
|
+
CSV.read(@options[:filename], { headers: @options[:headers] }).count if read_from_file?
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def initialize_csv
|
29
|
+
headers = @options[:headers].is_a?(String) ? @options[:headers].split(',') : @options[:headers]
|
30
|
+
|
31
|
+
csv_options = {
|
32
|
+
headers: headers,
|
33
|
+
header_converters: :symbol,
|
34
|
+
converters: [:all]
|
35
|
+
}
|
36
|
+
|
37
|
+
stream = read_from_file? ? File.open(@options[:filename]) : @options[:filename]
|
38
|
+
CSV.new(stream, csv_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def read_from_file?
|
42
|
+
@options[:filename] != $stdin
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Chronicle
|
2
|
+
module Etl
|
3
|
+
module Extractors
|
4
|
+
class Extractor
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options.transform_keys!(&:to_sym)
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
def results_count; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require_relative 'stdin'
|
20
|
+
require_relative 'csv'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Chronicle
|
4
|
+
module Etl
|
5
|
+
module Loaders
|
6
|
+
class Csv < Chronicle::Etl::Loaders::Loader
|
7
|
+
def initialize(options={})
|
8
|
+
super(options)
|
9
|
+
@rows = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(result)
|
13
|
+
if (result.values)
|
14
|
+
@rows << result.values
|
15
|
+
else
|
16
|
+
@rows << result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def finish
|
21
|
+
z = $stdout
|
22
|
+
CSV(z) do |csv|
|
23
|
+
@rows.each do |row|
|
24
|
+
csv << row
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Chronicle
|
2
|
+
module Etl
|
3
|
+
module Loaders
|
4
|
+
class Loader
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def start; end
|
10
|
+
|
11
|
+
def first_load; end
|
12
|
+
|
13
|
+
def load
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def finish; end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require_relative 'stdout'
|
24
|
+
require_relative 'csv'
|
25
|
+
require_relative 'table'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'table_print'
|
2
|
+
|
3
|
+
module Chronicle
|
4
|
+
module Etl
|
5
|
+
module Loaders
|
6
|
+
class Table < Chronicle::Etl::Loaders::Loader
|
7
|
+
def initialize(options)
|
8
|
+
super(options)
|
9
|
+
@rows = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(result)
|
13
|
+
@rows << result
|
14
|
+
end
|
15
|
+
|
16
|
+
def finish
|
17
|
+
tp @rows
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Chronicle::Etl::Runner
|
2
|
+
def initialize(options)
|
3
|
+
@options = options
|
4
|
+
|
5
|
+
instantiate_etl_classes
|
6
|
+
end
|
7
|
+
|
8
|
+
def run!
|
9
|
+
progress_bar = Chronicle::Etl::Utils::ProgressBarWrapper.new(@extractor.results_count)
|
10
|
+
@loader.start
|
11
|
+
|
12
|
+
@extractor.extract do |result, i|
|
13
|
+
@loader.first_load(result) if i == 0
|
14
|
+
|
15
|
+
transformed_data = @transformer.transform(result)
|
16
|
+
@loader.load(transformed_data)
|
17
|
+
|
18
|
+
progress_bar.increment
|
19
|
+
end
|
20
|
+
|
21
|
+
progress_bar.finish
|
22
|
+
@loader.finish
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def instantiate_etl_classes
|
28
|
+
@extractor = get_etl_class(:extractor, @options[:extractor][:name]).new(@options[:extractor][:options])
|
29
|
+
@transformer = get_etl_class(:transformer, @options[:transformer][:name]).new(@options[:transformer][:options])
|
30
|
+
@loader = get_etl_class(:loader, @options[:loader][:name]).new(@options[:loader][:options])
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_etl_class(phase, name)
|
34
|
+
klass_name = "Chronicle::Etl::#{phase.to_s.capitalize}s::#{name.capitalize}"
|
35
|
+
Object.const_get(klass_name)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Chronicle
|
2
|
+
module Etl
|
3
|
+
module Transformers
|
4
|
+
class Transformer
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def transform data
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require_relative 'null'
|
18
|
+
require_relative 'json'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ruby-progressbar'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
module Chronicle
|
5
|
+
module Etl
|
6
|
+
module Utils
|
7
|
+
class ProgressBarWrapper
|
8
|
+
def initialize(count)
|
9
|
+
return unless tty?
|
10
|
+
|
11
|
+
@pbar = ProgressBar.create(
|
12
|
+
format: '%b%i %c/%C (%P%%) %a %e Rate: %R',
|
13
|
+
remainder_mark: '░',
|
14
|
+
progress_mark: '▓'.colorize(:light_green),
|
15
|
+
starting_time: 0,
|
16
|
+
lenth: 200,
|
17
|
+
throttle_rate: 0.1,
|
18
|
+
total: count,
|
19
|
+
unknown_progress_animation_steps: ['▓░░░', '░▓░░', '░░▓░', '░░░▓']
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def increment
|
24
|
+
@pbar&.increment
|
25
|
+
end
|
26
|
+
|
27
|
+
def log(message)
|
28
|
+
@pbar&.log message
|
29
|
+
end
|
30
|
+
|
31
|
+
def finish
|
32
|
+
@pbar&.finish
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def tty?
|
38
|
+
$stdout.isatty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chronicle-etl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Louis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.20'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.20'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: table_print
|
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: ruby-progressbar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.17'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.17'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.9'
|
125
|
+
description: Chronicle-ETL allows you to extract personal data from a variety of services,
|
126
|
+
transformer it, and load it.
|
127
|
+
email:
|
128
|
+
- andrew@hyfen.net
|
129
|
+
executables:
|
130
|
+
- chronicle-etl
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rspec"
|
136
|
+
- ".travis.yml"
|
137
|
+
- CODE_OF_CONDUCT.md
|
138
|
+
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- bin/console
|
144
|
+
- bin/setup
|
145
|
+
- chronicle-etl.gemspec
|
146
|
+
- exe/chronicle-etl
|
147
|
+
- lib/chronicle/etl.rb
|
148
|
+
- lib/chronicle/etl/cli.rb
|
149
|
+
- lib/chronicle/etl/extractors/csv.rb
|
150
|
+
- lib/chronicle/etl/extractors/extractor.rb
|
151
|
+
- lib/chronicle/etl/extractors/stdin.rb
|
152
|
+
- lib/chronicle/etl/loaders/csv.rb
|
153
|
+
- lib/chronicle/etl/loaders/loader.rb
|
154
|
+
- lib/chronicle/etl/loaders/stdout.rb
|
155
|
+
- lib/chronicle/etl/loaders/table.rb
|
156
|
+
- lib/chronicle/etl/runner.rb
|
157
|
+
- lib/chronicle/etl/transformers/json.rb
|
158
|
+
- lib/chronicle/etl/transformers/null.rb
|
159
|
+
- lib/chronicle/etl/transformers/transformer.rb
|
160
|
+
- lib/chronicle/etl/utils/progress_bar_wrapper.rb
|
161
|
+
- lib/chronicle/etl/version.rb
|
162
|
+
homepage: https://github.com/chronicle-app
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata:
|
166
|
+
homepage_uri: https://github.com/chronicle-app
|
167
|
+
source_code_uri: https://github.com/chronicle-app/chronicle-etl
|
168
|
+
changelog_uri: https://github.com/chronicle-app/chronicle-etl
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubygems_version: 3.0.3
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: ETL tool for personal data
|
188
|
+
test_files: []
|