anki_auto_lookup 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/anki_auto_lookup.gemspec +27 -0
- data/lib/.DS_Store +0 -0
- data/lib/anki_auto_lookup.rb +86 -0
- data/lib/anki_auto_lookup/version.rb +3 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd26f19274c37d412551bb429183fdab52e91a59
|
4
|
+
data.tar.gz: 69918b15acaf162db89ac7e1179c108b7accac37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 197074c33fdb5f8cabdb4a035c18447f59905e1002ae450a5cc24a92b8ccdcfb51f8c6744612d4b5708aacc312a7ecc517adc065bd38bd6cad0487489769851f
|
7
|
+
data.tar.gz: b3552f041c6cd7f7372a67cbcfb79c23a149262922066680b50552a5c580bbd7c4060878f86efc064530de9ed3801eb88bd0e216a60b851ed42a0bd107994e75
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gary Bethea
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# AnkiAutoLookup
|
2
|
+
|
3
|
+
Anki_auto_lookup scrapes Google Translate. Whether you type in an English or Chinese word, it will find the definition, pinyin, and a recording of the Chinese word being spoken. Anki_auto_lookup stores all this information in a CSV text database for portability before creating a text file that can be uploaded to your Anki decks. The Anki deck's notes will have the English word on one side and the Chinese characters, pinyin, and recording on the other.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'anki_auto_lookup'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install anki_auto_lookup
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Anki_auto_lookup is fairly self-explanatory.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/OldGareBear/anki_auto_lookup/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'anki_auto_lookup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "anki_auto_lookup"
|
8
|
+
spec.version = AnkiAutoLookup::VERSION
|
9
|
+
spec.authors = ["Gary Bethea"]
|
10
|
+
spec.email = ["betheagary@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{anki_auto_lookup automatically translates English or Chinese words, downloads Chinese audio files, and generate Anki-compatible text files}
|
13
|
+
|
14
|
+
spec.description = %q{Anki_auto_lookup scrapes Google Translate. Whether you type in an English or Chinese word, it will find the definition, pinyin, and a recording of the Chinese word being spoken. Anki_auto_lookup stores all this information in a CSV text database for portability before creating a text file that can be uploaded to your Anki decks. The Anki deck's notes will have the English word on one side and the Chinese characters, pinyin, and recording on the other.}
|
15
|
+
|
16
|
+
spec.homepage = "https://github.com/OldGareBear/anki_auto_lookup"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
|
27
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "anki_auto_lookup/version"
|
2
|
+
require 'rest-client'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'uri'
|
5
|
+
require 'CSV'
|
6
|
+
|
7
|
+
class AnkiAutoLookup
|
8
|
+
attr_reader :english, :character, :pinyin, :audio_file_name, :temp_db
|
9
|
+
|
10
|
+
@@english_url = 'https://translate.google.com/translate_a/single?client=t&sl=en&tl=zh-CN&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&oc=1&otf=2&rom=1&ssel=5&tsel=5&q='
|
11
|
+
@@chinese_url = 'https://translate.google.com/translate_a/single?client=t&sl=zh-CN&tl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&pc=1&oc=1&otf=1&ssel=0&tsel=0&q='
|
12
|
+
@@match_google = /\p{Word}+\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*\s*\p{Word}*/
|
13
|
+
@@audio_url = 'https://translate.google.com/translate_tts?ie=UTF-8&q=<CHINESE_WORD>&tl=zh-CN&total=1&idx=0&textlen=6&client=t'
|
14
|
+
|
15
|
+
def self.start
|
16
|
+
puts "Would you like to type in the Chinese or the English word? c/e"
|
17
|
+
self.new(gets.downcase =~ /c/ ? 'Chinese' : 'English')
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(language)
|
21
|
+
@language = language
|
22
|
+
@temp_db = []
|
23
|
+
get_and_process_input
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_and_process_input
|
27
|
+
puts "Type the #{@language} word you'd like to translate, or type 'q' to exit and save.\n"
|
28
|
+
@word = gets.chomp
|
29
|
+
quit_and_push if @word.downcase == 'q'
|
30
|
+
@percent_encoded_word = URI::encode(@word)
|
31
|
+
get_def_and_pinyin
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_def_and_pinyin
|
35
|
+
url = (@language == "Chinese") ? @@chinese_url : @@english_url
|
36
|
+
raw_xhr = RestClient.get("#{url}#{@percent_encoded_word}", 'User-Agent' => 'Ruby')
|
37
|
+
google_results_arr = raw_xhr.force_encoding("UTF-8").scan(@@match_google)
|
38
|
+
parse_google_results(google_results_arr)
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_google_results(arr)
|
42
|
+
@english = (@language == "Chinese") ? arr[0] : @word
|
43
|
+
@character = (@language == "Chinese") ? @word : arr[0]
|
44
|
+
@pinyin = arr[2]
|
45
|
+
puts "#{arr[0]} #{@pinyin}"
|
46
|
+
get_audio(URI::encode(@character))
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_audio(percent_encoded_character)
|
50
|
+
@percent_encoded_character = percent_encoded_character
|
51
|
+
audio_url = @@audio_url.sub('<CHINESE_WORD>', @percent_encoded_character)
|
52
|
+
sanitized_english_word = @english.gsub(' ', '_')
|
53
|
+
File.open("#{sanitized_english_word}.mp3", "wb") do |file|
|
54
|
+
file.print open(audio_url).read
|
55
|
+
end
|
56
|
+
@audio_file_name = "#{sanitized_english_word}.mp3"
|
57
|
+
add_to_temp_db
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_to_temp_db
|
61
|
+
@temp_db << [@english, @character, @pinyin, @audio_file_name]
|
62
|
+
get_and_process_input
|
63
|
+
end
|
64
|
+
|
65
|
+
def quit_and_push
|
66
|
+
db = CSV.read('dictionary.txt')
|
67
|
+
@temp_db.each { |entry| db << entry }
|
68
|
+
CSV.open('dictionary.txt', 'w') do |csv|
|
69
|
+
db.each { |line| csv << line }
|
70
|
+
end
|
71
|
+
puts "Good job today! Do you want to create a new Anki file to add to your deck? y/n"
|
72
|
+
convert_to_anki if gets.downcase =~ /y/
|
73
|
+
end
|
74
|
+
|
75
|
+
def convert_to_anki
|
76
|
+
dict = CSV.read('dictionary.txt')
|
77
|
+
anki = File.open('anki.txt', 'w')
|
78
|
+
dict.each do |row|
|
79
|
+
anki.puts "#{row[0]}\t#{row[1]} #{row[2]} [sound:#{row[3]}]"
|
80
|
+
end
|
81
|
+
anki.close
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
AnkiAutoLookup.start
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anki_auto_lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gary Bethea
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Anki_auto_lookup scrapes Google Translate. Whether you type in an English
|
42
|
+
or Chinese word, it will find the definition, pinyin, and a recording of the Chinese
|
43
|
+
word being spoken. Anki_auto_lookup stores all this information in a CSV text database
|
44
|
+
for portability before creating a text file that can be uploaded to your Anki decks.
|
45
|
+
The Anki deck's notes will have the English word on one side and the Chinese characters,
|
46
|
+
pinyin, and recording on the other.
|
47
|
+
email:
|
48
|
+
- betheagary@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .DS_Store
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- anki_auto_lookup.gemspec
|
60
|
+
- lib/.DS_Store
|
61
|
+
- lib/anki_auto_lookup.rb
|
62
|
+
- lib/anki_auto_lookup/version.rb
|
63
|
+
homepage: https://github.com/OldGareBear/anki_auto_lookup
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: anki_auto_lookup automatically translates English or Chinese words, downloads
|
87
|
+
Chinese audio files, and generate Anki-compatible text files
|
88
|
+
test_files: []
|