papago 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/papago +28 -0
- data/lib/papago/configuration.rb +18 -0
- data/lib/papago/translator.rb +35 -0
- data/lib/papago/version.rb +3 -0
- data/lib/papago.rb +18 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5feb091b95a7beb3f4fa4decd5dfeebfc0c93a121f237c7b48b6a240fde57e49
|
4
|
+
data.tar.gz: 1287c7cbc52e2ae05087c6410be5743cba14de5662cc5774e941971eb78b0572
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c1204d5916cd31df5def351db1c19f55e68421fd5ac2c62d4ea1fec4044bb710bfe239a3a258f7df6b1577c60a7dadfd2af6eee852ff1ac0af39410ec597b1e
|
7
|
+
data.tar.gz: 12ca99c431f1a387730f29c7a3a62a4fc02ff9c3af295bf1f5c0703fab2f23247bc276df141ea91488e6571ec232a9667074adb5590bfc44c917f1556ec8cf75
|
data/bin/papago
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'papago'
|
4
|
+
require 'treely'
|
5
|
+
require 'lolcat/lol'
|
6
|
+
require 'active_support/core_ext/object/blank'
|
7
|
+
require 'active_support/core_ext/string/filters'
|
8
|
+
require 'mercenary'
|
9
|
+
|
10
|
+
Papago.configure do |config|
|
11
|
+
config.keyfrom = ENV['PAPAGO_CLIENT_ID']
|
12
|
+
config.key = ENV['PAPAGO_CLIENT_SECRET']
|
13
|
+
end
|
14
|
+
|
15
|
+
Mercenary.program(:papago) do |program|
|
16
|
+
program.version Papago::VERSION
|
17
|
+
program.syntax 'papago netease'
|
18
|
+
|
19
|
+
program.action do |args, options|
|
20
|
+
if args.present?
|
21
|
+
contents = Papago.translate(args.join(%{ })).contents
|
22
|
+
contents.then { |_| Treely.tree(_) }
|
23
|
+
.then { |_| StringIO.new(_.to_s.remove(' []')) }
|
24
|
+
.then { |_| Lol.cat(_, { freq: 0.25, spread: 8.0, os: rand(256) }) }
|
25
|
+
puts %{}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Papago
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :key
|
4
|
+
attr_accessor :keyfrom
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configuration=(config)
|
12
|
+
@configuration = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield configuration
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Papago
|
2
|
+
class Translator
|
3
|
+
def initialize(text)
|
4
|
+
@request = URI('https://fanyi.youdao.com/openapi.do')
|
5
|
+
@request.query = URI.encode_www_form({
|
6
|
+
:keyfrom => Papago[:keyfrom],
|
7
|
+
:key => Papago[:key],
|
8
|
+
:type => 'data',
|
9
|
+
:doctype => 'json',
|
10
|
+
:version => '1.1',
|
11
|
+
:q => text
|
12
|
+
})
|
13
|
+
|
14
|
+
build_context!
|
15
|
+
end
|
16
|
+
|
17
|
+
def contents
|
18
|
+
[
|
19
|
+
{
|
20
|
+
name: "#{@context.fetch(:query)} [#{@context.dig(:basic, :phonetic)}]",
|
21
|
+
contents: [
|
22
|
+
{
|
23
|
+
name: @context.fetch(:translation).join(%{ }),
|
24
|
+
contents: (@context.dig(:basic, :explains) || []).map { |explain| { name: explain } }
|
25
|
+
}
|
26
|
+
] + @context.fetch(:web, []).map { |explain| { name: "#{explain.fetch(:key)}: #{explain.fetch(:value).join(%{ })}" } }
|
27
|
+
}
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_context!
|
32
|
+
@context = JSON.parse(@request.read, symbolize_names: true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/papago.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
require 'papago/version'
|
5
|
+
require 'papago/translator'
|
6
|
+
require 'papago/configuration'
|
7
|
+
|
8
|
+
module Papago
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def translate(text)
|
12
|
+
Translator.new(text)
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](name)
|
16
|
+
configuration.send(name)
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: papago
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- matark
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mercenary
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: lolcat
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '99.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '99.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: treely
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description:
|
84
|
+
email: matark@naver.com
|
85
|
+
executables:
|
86
|
+
- papago
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- bin/papago
|
91
|
+
- lib/papago.rb
|
92
|
+
- lib/papago/configuration.rb
|
93
|
+
- lib/papago/translator.rb
|
94
|
+
- lib/papago/version.rb
|
95
|
+
homepage: https://opensource.matark.de/papago
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubygems_version: 3.0.3
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: A simple command-line translator
|
118
|
+
test_files: []
|