wduck 0.1.2alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26612b0edd4d044fa649c7db95a8a3bf91c1c172
4
+ data.tar.gz: e078673d11571a4e749a79649df8bfe42f8d1b99
5
+ SHA512:
6
+ metadata.gz: 3f13ebdeb3a581a616c965a60c57158f09ac70d5931cf0dcfc9d22dd607084cc5bf63f078f9ee4f1a6376b6e3f86cf38ad44b801eeb1523485acb130356cfff7
7
+ data.tar.gz: f4f0ae83d3de765e7eaed661fed75aab1af2fe62c66152874c33adfc705f62432122c887c27ccd1adedcdac38e691f2f691f87477221a1712c3b7b59a7b32ab7
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = wduck
2
+
3
+ Describe your project here
4
+
5
+ :include:wduck.rdoc
6
+
data/bin/wduck ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ begin # XXX: Remove this begin/rescue before distributing your app
4
+ require 'wduck'
5
+ rescue LoadError
6
+ STDERR.puts "In development, you need to use `bundle exec bin/wduck` to run your app"
7
+ STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
+ STDERR.puts "Feel free to remove this message from bin/wduck now"
9
+ exit 64
10
+ end
11
+
12
+ include GLI::App
13
+
14
+ program_desc 'A command line tool to use zero click feature of DDG'
15
+
16
+ version Wduck::VERSION
17
+
18
+ command :wiki do |c|
19
+ c.desc 'Describe a switch to wiki'
20
+ c.switch :s
21
+
22
+ c.desc 'Describe a flag to wiki'
23
+ c.default_value 'default'
24
+ c.flag :f
25
+ c.action do |global_options,options,args|
26
+
27
+ # Your command logic here
28
+
29
+ # If you have any errors, just raise them
30
+ # raise "that command made no sense"
31
+
32
+ puts "wiki command ran"
33
+ end
34
+ end
35
+
36
+ desc 'Access the DuckDuckGo Zero Click Info API to get result, see https://api.duckduckgo.com/goodies '
37
+ arg_name 'Search term'
38
+ command :duck do |c|
39
+ c.action do |global_options,options,args|
40
+ query = args.join ' '
41
+ if query.empty?
42
+ puts "Please enter an argument of search term"
43
+ else
44
+ w = Wduck::Duck::Ddg.new(query)
45
+ w.result
46
+ end
47
+ end
48
+ end
49
+
50
+ pre do |global,command,options,args|
51
+ # Pre logic here
52
+ # Return true to proceed; false to abort and not call the
53
+ # chosen command
54
+ # Use skips_pre before a command to skip this block
55
+ # on that command only
56
+ true
57
+ end
58
+
59
+ post do |global,command,options,args|
60
+ # Post logic here
61
+ # Use skips_post before a command to skip this
62
+ # block on that command only
63
+ end
64
+
65
+ on_error do |exception|
66
+ # Error logic here
67
+ # return false to skip default error handling
68
+ true
69
+ end
70
+
71
+ exit run(ARGV)
data/lib/wduck.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'wduck/version'
2
+ require 'wduck/duck'
3
+ # you just need to require this one file in your bin file
4
+ module Wduck
5
+ end
data/lib/wduck/duck.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Wduck
2
+
3
+ module Duck
4
+ require 'wduck/duck_helper'
5
+
6
+ class Ddg
7
+ include Wduck::DuckHelper
8
+
9
+ def initialize(query)
10
+ @parsed_data = get_json_data(query)
11
+ end
12
+
13
+ def result
14
+ heading(@parsed_data)
15
+ source(@parsed_data)
16
+
17
+ if @parsed_data["Answer"].empty?
18
+ abstract_text(@parsed_data)
19
+
20
+ if @parsed_data["AbstractText"].empty?
21
+ @parsed_data["RelatedTopics"].each_with_index do |result, index|
22
+ result_text(index, result)
23
+ end
24
+ end
25
+
26
+ else
27
+ answer(@parsed_data)
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,52 @@
1
+ module Wduck
2
+ require 'httpclient'
3
+ require 'json'
4
+ require 'htmlentities'
5
+ require 'rainbow'
6
+
7
+ module DuckHelper
8
+
9
+ API_URL = "https://api.duckduckgo.com/"
10
+ FORMAT = "json"
11
+
12
+ def get_json_data(query)
13
+ http = HTTPClient.new(agent_name: "ddg.rb")
14
+ args = { q: query, format: FORMAT }
15
+ data = http.get_content(API_URL, args )
16
+ JSON.parse data
17
+ end
18
+
19
+ def make_sane(value)
20
+ # remove html tags, convert to proper utf codes
21
+
22
+ coder = HTMLEntities.new
23
+ re = /<("[^"]*"|'[^']*'|[^'">])*>/
24
+ coder.decode(value.gsub(re, '')) #remove html tags, then make proper unicode conversion
25
+ end
26
+
27
+ def heading(parsed_data)
28
+ unless parsed_data["Heading"].empty?
29
+ puts make_sane(parsed_data["Heading"]).foreground(:red).background(:white)
30
+ end
31
+ end
32
+
33
+ def source(parsed_data)
34
+ unless parsed_data["AbstractSource"].empty?
35
+ puts "Source: #{make_sane(parsed_data["AbstractSource"])}".color(:yellow)
36
+ end
37
+ end
38
+
39
+ def abstract_text(parsed_data)
40
+ puts make_sane(parsed_data["AbstractText"]).color(:green)
41
+ end
42
+
43
+ def result_text(index, result)
44
+ puts "#{(index + 1)}, #{make_sane(result["Text"]).color(:green)}" if result["Text"]
45
+ end
46
+
47
+ def answer(parsed_data)
48
+ puts make_sane(parsed_data["Answer"]).color(:green)
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,3 @@
1
+ module Wduck
2
+ VERSION = '0.1.2alpha'
3
+ end
data/wduck.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = wduck
2
+
3
+ Generate this with
4
+ wduck rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wduck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2alpha
5
+ platform: ruby
6
+ authors:
7
+ - Vysakh Sreeenivasan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rdoc
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
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: httpclient
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: htmlentities
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: rainbow
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: gli
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 2.7.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.7.0
111
+ description: A command line tool to get instant zero click result from ddg
112
+ email: diplomatv@gmail.com
113
+ executables:
114
+ - wduck
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - README.rdoc
118
+ - wduck.rdoc
119
+ files:
120
+ - bin/wduck
121
+ - lib/wduck/version.rb
122
+ - lib/wduck.rb
123
+ - lib/wduck/duck.rb
124
+ - lib/wduck/duck_helper.rb
125
+ - README.rdoc
126
+ - wduck.rdoc
127
+ homepage: http://github.com/vysakh0/wduck
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>'
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.1
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.0.2
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: A command line tool for accessing zero click feature of Duck duck go
152
+ test_files: []