s3_download_by_date 0.1.5 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODhlMmIwYWY4Y2EwYTNmMjI2YjQzYjFmMjkxMTY4MTcyN2Y5NzY3YQ==
5
- data.tar.gz: !binary |-
6
- YjE4ZDUwYzNkNDQ4Nzk5MTJiM2VkZDVlMzhlM2U5YWFlM2MxM2UyYw==
2
+ SHA1:
3
+ metadata.gz: 42355945432c4611f873ccd0f06097a5efdbae0c
4
+ data.tar.gz: 2fc954497f44325e226566ecf787d2b07c797981
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZWMyOGE1YTMwY2FkZjcxMDJjMjAwYzdmMjY4ZmFmNDM1MjE0Yjk1NmQ3NmQ1
10
- ODA2OTYyMDgzNDY3OTBiMjhiYTI3NTdkNGMyMjllNDM5NGI0MGUzMWNjMmEx
11
- ZTMwMTBiYWRmMmQ5NjA2NjVmOGQ1ZDliZjBkOTE3NzZkNWE3OTQ=
12
- data.tar.gz: !binary |-
13
- YWM4ZThlZDVhYjQwYzE2Njg5NjUyZjkwMjU0ZDVjYTU5MWU4YWZkZDYwYjli
14
- OWEwOGE0ZTc0ZTcwNDRmMjI2NDY4OWJkZjUyYmNjMDFmYjZmMTg0ZjA4YjBk
15
- NzBlYTRhYzA1ZmM0ZWNlOTczMThkOWQ4MDFiY2JjMGYzMjU4MjE=
6
+ metadata.gz: 11bb79df712ad1f15b148f32324a955475ccfc142a020ef2e6cba7b6f86c0aaa8f6e019945ebda69fc59801613925f1fdf7b334d8d9910384a0e8d33d1ba0396
7
+ data.tar.gz: 2b32215a4c9d8f4627f8ab854ab737593adf2513e9d9d25d41c4e9a51130b18eaaed30e100b8ab75454d1a060d09e2d72db9d20f87db05e65f87b88748ed1d29
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Glide Talk, LTD.
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,63 @@
1
+ # S3 Download by date range [![Gem Version](https://badge.fury.io/rb/s3_download_by_date.svg)](http://badge.fury.io/rb/s3_download_by_date)
2
+
3
+ S3 Download files by modifed date (Range)
4
+
5
+ ## Installation
6
+
7
+ $ gem install s3-download-by-date
8
+
9
+
10
+ ## Configuration
11
+ add to your ~/.bash_profile (~/.zprofile if using ZSH)
12
+
13
+ ```bash
14
+ export REGION='eu-west-1' (default to us-east-1)
15
+ export AWS_ACCESS_KEY="YOUR AWS KEY ID"
16
+ export AWS_SECRET_KEY="YOUR AWS SECRET KEY"
17
+
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ````bash
23
+ s3download range --bucket=s3-bucket-name --prefix=folder_or_file_prefix --from='yesterday at noon' --to='today at noon' --save-to=~/Downloads
24
+ ````
25
+
26
+ s3download uses [Chronic](https://github.com/mojombo/chronic) library to set the --from and --to
27
+
28
+
29
+ Or download by timezone
30
+
31
+ ````bash
32
+ s3download range --timezone='Eastern Time (US & Canada)' ' --bucket=s3-bucket-name --prefix=folder_or_file_prefix --from='yesterday at noon' --to='today at noon' --save-to=~/Downloads
33
+ ````
34
+
35
+ **Getting a list of timezones strings:**
36
+
37
+ ````bash
38
+ s3download list_timezones
39
+ ````
40
+
41
+ ````javascript
42
+ {
43
+ "International Date Line West": "Pacific/Midway",
44
+ "Midway Island": "Pacific/Midway",
45
+ "American Samoa": "Pacific/Pago_Pago",
46
+ "Hawaii": "Pacific/Honolulu",
47
+ "Alaska": "America/Juneau",
48
+ "Pacific Time (US & Canada)": "America/Los_Angeles"
49
+ .
50
+ .
51
+ .
52
+ }
53
+ ````
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
61
+
62
+ ## LICENSE
63
+ s3_download_by_date is released under [MIT License](http://www.opensource.org/licenses/MIT)
data/bin/s3download CHANGED
@@ -1,115 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
- require 'aws-sdk'
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
4
3
  require 'thor'
5
- require 'chronic'
6
- require 'progressbar'
7
- require 'active_support/time'
8
- require 'fileutils'
9
- require 'json'
4
+ require 'S3download'
10
5
 
11
- class S3Downloader < Thor
12
- default_task :show_help
13
- AWS.config({
14
- :access_key_id => ENV['AWS_ACCESS_KEY'],
15
- :secret_access_key => ENV['AWS_SECRET_KEY'],
16
- :region => ENV['REGION'] || 'us-east-1'
17
- })
18
-
19
- @@s3 = AWS::S3.new
20
-
21
- desc 'list_timezones', 'list timezones'
22
- def list_timezones
23
- puts JSON.pretty_generate(ActiveSupport::TimeZone::MAPPING)
24
- end
25
-
26
- desc 'show_help', 'show full help'
27
- def show_help
28
- puts <<-HELP
29
- Download S3 files by range (date)
30
-
31
- Setup:
32
- export REGION='eu-west-1' (default to us-east-1)
33
- export AWS_ACCESS_KEY="YOUR AWS KEY ID"
34
- export AWS_SECRET_KEY="YOUR AWS SECRET KEY"
35
-
36
- Usage:
37
- s3download range --timezone='Eastern Time (US & Canada)' --bucket=S3 Bucket Name --prefix=folder inside the specified bucket --save-to=Location of downloaded files
38
-
39
- Options:
40
- --bucket=S3 Bucket Name # S3 Bucket Name
41
- --prefix=folder inside the specified bucket # Folder inside the specified bucket
42
- [--from=From in a natural language date/time like yesterday, last week, etc...]
43
- # Default: 2014-08-04 00:00:00 +0300
44
- [--to=To in a natural language date/time like yesterday, last week, etc...]
45
- # Default: 2014-08-04 23:59:59 +0300
46
- --timezone filter files by date [defaults to UTC] ex: "Eastern Time (US & Canada)
47
- --save-to=Location of downloaded files # The target directory where download files be stored
48
-
49
- Utility (Get a list of timezones strings):
50
- s3download list_timezones
51
- {
52
- "International Date Line West": "Pacific/Midway",
53
- "Midway Island": "Pacific/Midway",
54
- "American Samoa": "Pacific/Pago_Pago",
55
- "Hawaii": "Pacific/Honolulu",
56
- "Alaska": "America/Juneau",
57
- "Pacific Time (US & Canada)": "America/Los_Angeles"
58
- .
59
- .
60
- .
61
- }
62
- HELP
63
- end
64
-
65
- desc 'download', 'Download S3 files by range (date)'
66
- method_option :bucket, :required => true, :alias => 'b', :desc => 'S3 Bucket Name', :banner => 'S3 Bucket Name'
67
- method_option :prefix, :required => true, :alias => 'f', :desc => 'Folder inside the specified bucket', :banner => 'folder inside the specified bucket'
68
- method_option :from, :default => Chronic.parse('today at 00:00:00'), :banner => 'From in a natural language date/time like yesterday, \'last week\', etc...'
69
- method_option :to, :default => Chronic.parse('today at 23:59:59'), :banner => 'To in a natural language date/time like yesterday, \'last week\', etc...'
70
- method_option :save_to, :required => true, :desc => 'the target directory where download files be stored', :banner => 'Location of downloaded files'
71
- method_option :debug, :default => false, :type => :boolean, :desc => 'the target directory where download files be stored'
72
- method_option :timezone, :default => 'UTC', :banner => 'timezone to filter files by date [UTC] ex: "Eastern Time (US & Canada)"'
73
- def range
74
- timezone = options[:timezone]
75
- puts "TimeZone: #{timezone}"
76
- bucket = @@s3.buckets[options[:bucket]].objects.with_prefix(options[:prefix])
77
- from = Chronic.parse("#{options[:from]}").in_time_zone(timezone)
78
- to = Chronic.parse("#{options[:to]}").in_time_zone(timezone)
79
- puts "From: #{from}"
80
- puts "To: #{to}"
81
- range = from..to
82
- target = File.expand_path(options[:save_to])
83
-
84
- say("download target: #{options[:save_to]}/#{options[:prefix]}", color=:cyan) if options[:debug]
85
- say("Range: #{range}", color=:green) if options[:debug]
86
-
87
- ProgressBar.new("Filter Files", bucket.count) do |pbar|
88
- FileUtils.mkdir_p "#{target}"
89
- File.open("#{target}/download_info.txt", "w") {|f| f.write("#{Time.now} - Downloaded bucket #{options[:bucket]}/#{options[:prefix]} from: #{from} - to #{to}")}
90
-
91
- bucket.each do |object|
92
- # puts "timezone: #{timezone}" if options[:debug]
93
- # puts "object last modified: #{object.last_modified}" if options[:debug]
94
- # puts "object last modified in timezone: #{object.last_modified.in_time_zone(timezone)}" if options[:debug]
95
- # puts "object falls in range: #{range}? => #{range.cover?(object.last_modified.in_time_zone(timezone))}"
96
- if range.cover?(object.last_modified.in_time_zone(timezone))
97
- say("Downloading #{object.key} #{object.last_modified.in_time_zone(timezone)}\n", color=:white) if options[:debug]
98
- FileUtils.mkdir_p "#{target}/#{object.key.match(/(.+)\//)[1]}"
99
-
100
- begin
101
- File.open("#{target}/#{object.key}", "w") do |f|
102
- f.write(object.read)
103
- end
104
- rescue Exception => e
105
- puts "Unable to save file: #{e}"
106
- end
107
- end
108
- pbar.inc
109
- end
110
- end
111
- end
6
+ def help
7
+ S3download::Cli.start(%w{help fetch})
8
+ end
112
9
 
10
+ begin
11
+ ENV["THOR_DEBUG"] = "1"
12
+ S3download::Cli.start
13
+ rescue Thor::RequiredArgumentMissingError => e
14
+ puts "\e[31mMissing Arguments: #{e}\e[0m\n\n"
15
+ help
16
+ rescue Thor::InvocationError => e
17
+ puts "\e[31m#{e.to_s.gsub(/Usage:.+"/, '').chomp} but there's no such option\e[0m\n\n"
18
+ help
113
19
  end
114
20
 
115
- S3Downloader.start
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require File.expand_path('../lib/s3download', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "s3_download_by_date"
6
+ s.version = S3download::VERSION
7
+ s.authors = ["Ami Mahloof"]
8
+ s.email = "ami.mahloof@gmail.com"
9
+ s.homepage = "https://github.com/innovia/s3_download_by_date"
10
+ s.summary = "Download from S3 by date range"
11
+ s.description = "Download files by modified date range"
12
+ s.required_rubygems_version = ">= 1.3.6"
13
+ s.add_runtime_dependency 'thor', '~> 0.19', '>= 0.19.1'
14
+ s.add_runtime_dependency 'chronic', '~> 0.10', '>= 0.10.2'
15
+ s.add_runtime_dependency 'progressbar', '~> 0.21', '>= 0.21.0'
16
+ s.add_runtime_dependency 'aws-sdk', '~> 1.40', '>= 1.40.0'
17
+ s.add_runtime_dependency 'activesupport', '~> 4.1', '>= 4.1.4'
18
+ s.files = `git ls-files`.split($\).reject{|n| n =~ %r[png|gif\z]}.reject{|n| n =~ %r[^(test|spec|features)/]}
19
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
21
+ s.license = 'MIT'
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_download_by_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ami Mahloof
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.19'
20
- - - ! '>='
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.19.1
23
23
  type: :runtime
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0.19'
30
- - - ! '>='
30
+ - - '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.19.1
33
33
  - !ruby/object:Gem::Dependency
@@ -37,7 +37,7 @@ dependencies:
37
37
  - - ~>
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.10'
40
- - - ! '>='
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: 0.10.2
43
43
  type: :runtime
@@ -47,7 +47,7 @@ dependencies:
47
47
  - - ~>
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0.10'
50
- - - ! '>='
50
+ - - '>='
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.10.2
53
53
  - !ruby/object:Gem::Dependency
@@ -57,7 +57,7 @@ dependencies:
57
57
  - - ~>
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0.21'
60
- - - ! '>='
60
+ - - '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: 0.21.0
63
63
  type: :runtime
@@ -67,7 +67,7 @@ dependencies:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0.21'
70
- - - ! '>='
70
+ - - '>='
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.21.0
73
73
  - !ruby/object:Gem::Dependency
@@ -77,7 +77,7 @@ dependencies:
77
77
  - - ~>
78
78
  - !ruby/object:Gem::Version
79
79
  version: '1.40'
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.40.0
83
83
  type: :runtime
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.40'
90
- - - ! '>='
90
+ - - '>='
91
91
  - !ruby/object:Gem::Version
92
92
  version: 1.40.0
93
93
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,7 @@ dependencies:
97
97
  - - ~>
98
98
  - !ruby/object:Gem::Version
99
99
  version: '4.1'
100
- - - ! '>='
100
+ - - '>='
101
101
  - !ruby/object:Gem::Version
102
102
  version: 4.1.4
103
103
  type: :runtime
@@ -107,7 +107,7 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: '4.1'
110
- - - ! '>='
110
+ - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: 4.1.4
113
113
  description: Download files by modified date range
@@ -115,9 +115,15 @@ email: ami.mahloof@gmail.com
115
115
  executables:
116
116
  - s3download
117
117
  extensions: []
118
- extra_rdoc_files: []
118
+ extra_rdoc_files:
119
+ - README.md
120
+ - LICENSE
119
121
  files:
122
+ - .gitignore
123
+ - LICENSE
124
+ - README.md
120
125
  - bin/s3download
126
+ - s3_download_by_date.gemspec
121
127
  homepage: https://github.com/innovia/s3_download_by_date
122
128
  licenses:
123
129
  - MIT
@@ -128,17 +134,17 @@ require_paths:
128
134
  - lib
129
135
  required_ruby_version: !ruby/object:Gem::Requirement
130
136
  requirements:
131
- - - ! '>='
137
+ - - '>='
132
138
  - !ruby/object:Gem::Version
133
139
  version: '0'
134
140
  required_rubygems_version: !ruby/object:Gem::Requirement
135
141
  requirements:
136
- - - ! '>='
142
+ - - '>='
137
143
  - !ruby/object:Gem::Version
138
144
  version: 1.3.6
139
145
  requirements: []
140
146
  rubyforge_project:
141
- rubygems_version: 2.2.2
147
+ rubygems_version: 2.4.2
142
148
  signing_key:
143
149
  specification_version: 4
144
150
  summary: Download from S3 by date range