goog 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/goog +19 -22
- data/lib/goog.rb +1 -1
- metadata +1 -1
data/bin/goog
CHANGED
@@ -4,19 +4,16 @@ require 'nokogiri'
|
|
4
4
|
require 'cgi'
|
5
5
|
require 'yaml'
|
6
6
|
require 'uri'
|
7
|
+
require 'optparse'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
-h, --help Show this message
|
17
|
-
|
18
|
-
Date range types for -d option:
|
19
|
-
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: goog [options] [query]"
|
12
|
+
opts.on("-h", "--help", "Show this message") {
|
13
|
+
require 'goog'
|
14
|
+
puts <<END
|
15
|
+
#{opts}
|
16
|
+
DATE RANGE options for -d option:
|
20
17
|
h last hour
|
21
18
|
d last day (24 hours)
|
22
19
|
w last week
|
@@ -27,12 +24,12 @@ goog #{Goog::VERSION}
|
|
27
24
|
http://github.com/danchoi/goog
|
28
25
|
Author: Daniel Choi <dhchoi@gmail.com>
|
29
26
|
END
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
pages
|
34
|
-
|
35
|
-
|
27
|
+
exit
|
28
|
+
}
|
29
|
+
opts.on("-d", '--date-range [DATE RANGE]', 'Show results for date range. See below for options.') {|dr| options[:date_range] = dr }
|
30
|
+
opts.on("-n", '--num-pages [NUM PAGES]', 'Show NUM PAGES pages of results') {|pages| options[:pages] = pages.to_i }
|
31
|
+
opts.on("-c", '--color', 'Force color output') {options[:color] = true}
|
32
|
+
end.parse!
|
36
33
|
query = ARGV.join(' ')
|
37
34
|
unless query
|
38
35
|
abort "Please provide a search query"
|
@@ -45,10 +42,10 @@ if RUBY_VERSION !~ /^1.9/
|
|
45
42
|
abort "Requires Ruby 1.9"
|
46
43
|
end
|
47
44
|
query = "/search?q=#{CGI.escape query}"
|
48
|
-
if date_range
|
49
|
-
query += "&as_qdr=#{date_range}"
|
45
|
+
if options[:date_range]
|
46
|
+
query += "&as_qdr=#{options[:date_range]}"
|
50
47
|
end
|
51
|
-
(1..pages).each do |page|
|
48
|
+
(1..(options[:pages] || 1)).each do |page|
|
52
49
|
if query.nil?
|
53
50
|
exit
|
54
51
|
end
|
@@ -75,7 +72,7 @@ end
|
|
75
72
|
end
|
76
73
|
end
|
77
74
|
number = (page - 1) * 10 + (index + 1)
|
78
|
-
res = if STDOUT.tty?
|
75
|
+
res = if STDOUT.tty? || options[:color]
|
79
76
|
["#{number}. \e[36m#{title}\e[0m", excerpt, "\e[35m#{link }\e[0m"]
|
80
77
|
else
|
81
78
|
["#{number}. #{title}", excerpt, link]
|
data/lib/goog.rb
CHANGED