gtt-downloader 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/bin/console +6 -0
- data/bin/setup +7 -0
- data/exe/gtt-downloader +15 -0
- data/gtt-downloader.gemspec +35 -0
- data/lib/gtt/downloader.rb +91 -0
- data/lib/gtt/downloader/version.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3bbfc095bae2d3eec1fc87d27063d02261ab170e
|
4
|
+
data.tar.gz: fa8658813de84229b61e67ae7e1165ba266bc3d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57854972d25ddb4e6bcb191c631835c5c86339b39da4885008ae3b3bc73a58a7528eb85df39a160471fc4ff6b3a3c9f047e983a97b625296add98fe32417fcda
|
7
|
+
data.tar.gz: ffc1561159021403b4d0fa9407f1e05ebc457764207e83a12ac637ffc33b0531c545b669544d36d317e2f2b5a2034cc597b5fbde1edcf7c072cf263efbabe10b
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Seiei Miyagi
|
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,47 @@
|
|
1
|
+
# Gtt::Downloader
|
2
|
+
|
3
|
+
Download archive.zip from Google Translator Toolkit.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gtt-downloader'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gtt-downloader
|
20
|
+
|
21
|
+
Gtt::Downloader requires chromdriver:
|
22
|
+
|
23
|
+
$ brew install chromedriver
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
$ LABEL="example" GMAIL_ADDR="your gmail address" GMAIL_PASS="your gmail pass" gtt-downloader
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
- [x] download archive.zip(multiple files)
|
32
|
+
- [ ] download single file
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
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).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yasslab/gtt-downloader. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
43
|
+
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/gtt-downloader
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "gtt/downloader"
|
4
|
+
|
5
|
+
unless ENV['LABEL']
|
6
|
+
puts <<USAGE
|
7
|
+
Usage: gtt-downloader LABEL="example"
|
8
|
+
USAGE
|
9
|
+
exit 0
|
10
|
+
end
|
11
|
+
|
12
|
+
downloader = Gtt::Downloader.new
|
13
|
+
label = ENV['LABEL']
|
14
|
+
archive_path = downloader.download_label(label)
|
15
|
+
puts archive_path
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gtt/downloader/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gtt-downloader"
|
8
|
+
spec.version = Gtt::Downloader::VERSION
|
9
|
+
spec.authors = ["Seiei Miyagi"]
|
10
|
+
spec.email = ["hanachin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Download archive.zip from Google Translator Toolkit.}
|
13
|
+
spec.homepage = "https://github.com/yasslab/gtt-downloader"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "capybara"
|
30
|
+
spec.add_dependency "chromedriver-helper"
|
31
|
+
spec.add_dependency "selenium-webdriver"
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "pry"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "gtt/downloader/version"
|
2
|
+
require "capybara"
|
3
|
+
|
4
|
+
module Gtt
|
5
|
+
URL = 'http://translate.google.com/toolkit/'
|
6
|
+
|
7
|
+
class Downloader
|
8
|
+
def initialize(email = ENV['GMAIL_ADDR'], password = ENV['GMAIL_PASS'])
|
9
|
+
unless email && password
|
10
|
+
raise 'email or password is not set'
|
11
|
+
end
|
12
|
+
|
13
|
+
@email = email
|
14
|
+
@password = password
|
15
|
+
end
|
16
|
+
|
17
|
+
def download_label(label)
|
18
|
+
session = nil
|
19
|
+
|
20
|
+
Capybara.using_wait_time(wait_time) do
|
21
|
+
session = signed_in_session
|
22
|
+
|
23
|
+
session.click_on(label)
|
24
|
+
# FIXME ラベルが選択されアイテムが表示されるのを待つ
|
25
|
+
sleep 10
|
26
|
+
|
27
|
+
session.find('#select-menu-button').click
|
28
|
+
# FIXME ファイルが選択されるのを待つ
|
29
|
+
sleep 10
|
30
|
+
|
31
|
+
archive_path_helper do
|
32
|
+
session.find('#download-button').click
|
33
|
+
# FIXME ダウンロードを待つ
|
34
|
+
begin
|
35
|
+
sleep 1
|
36
|
+
end while session.windows.length != 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
ensure
|
40
|
+
session.cleanup!
|
41
|
+
session.driver.quit
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def archive_path_helper(&action)
|
47
|
+
previous_archive_paths = archive_paths
|
48
|
+
|
49
|
+
action.call
|
50
|
+
|
51
|
+
downloaded_archive_paths = archive_paths - previous_archive_paths
|
52
|
+
|
53
|
+
if downloaded_archive_paths.count.zero?
|
54
|
+
raise "Download failed"
|
55
|
+
end
|
56
|
+
|
57
|
+
if downloaded_archive_paths.count != 1
|
58
|
+
raise "Ambiguous archive_path: #{downloaded_archive_paths.inspect}"
|
59
|
+
end
|
60
|
+
|
61
|
+
downloaded_archive_paths[0]
|
62
|
+
end
|
63
|
+
|
64
|
+
def archive_paths
|
65
|
+
Dir.glob(File.expand_path('~/Downloads/archive*.zip'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def gtt_driver
|
69
|
+
unless Capybara.drivers.has_key?(:gtt_downloader)
|
70
|
+
Capybara.register_driver :gtt_downloader do |app|
|
71
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
:gtt_downloader
|
76
|
+
end
|
77
|
+
|
78
|
+
def signed_in_session
|
79
|
+
session = Capybara::Session.new(gtt_driver)
|
80
|
+
session.visit(::Gtt::URL)
|
81
|
+
session.fill_in 'Email', with: @email
|
82
|
+
session.fill_in 'Passwd', with: @password
|
83
|
+
session.click_on 'ログイン'
|
84
|
+
session
|
85
|
+
end
|
86
|
+
|
87
|
+
def wait_time
|
88
|
+
60
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gtt-downloader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seiei Miyagi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chromedriver-helper
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: selenium-webdriver
|
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: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
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: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
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
|
+
description:
|
98
|
+
email:
|
99
|
+
- hanachin@gmail.com
|
100
|
+
executables:
|
101
|
+
- gtt-downloader
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- CODE_OF_CONDUCT.md
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- exe/gtt-downloader
|
114
|
+
- gtt-downloader.gemspec
|
115
|
+
- lib/gtt/downloader.rb
|
116
|
+
- lib/gtt/downloader/version.rb
|
117
|
+
homepage: https://github.com/yasslab/gtt-downloader
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
allowed_push_host: https://rubygems.org
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.5
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Download archive.zip from Google Translator Toolkit.
|
142
|
+
test_files: []
|