pictate 0.1.1
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.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/bin/pictate +51 -0
- data/ext/.gitignore +0 -0
- data/lib/pictate.rb +83 -0
- data/test/helper.rb +18 -0
- data/test/test_pictate.rb +5 -0
- metadata +141 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.1.0"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
gem "selenium-webdriver", "~> 2.20"
|
15
|
+
gem "choice", "~> 0.1.6"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
childprocess (0.3.1)
|
5
|
+
ffi (~> 1.0.6)
|
6
|
+
choice (0.1.6)
|
7
|
+
ffi (1.0.11)
|
8
|
+
git (1.2.5)
|
9
|
+
jeweler (1.8.3)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rdoc
|
14
|
+
json (1.6.6)
|
15
|
+
multi_json (1.2.0)
|
16
|
+
rake (0.9.2.2)
|
17
|
+
rdoc (3.12)
|
18
|
+
json (~> 1.4)
|
19
|
+
rubyzip (0.9.6.1)
|
20
|
+
selenium-webdriver (2.20.0)
|
21
|
+
childprocess (>= 0.2.5)
|
22
|
+
ffi (~> 1.0)
|
23
|
+
multi_json (~> 1.0)
|
24
|
+
rubyzip
|
25
|
+
shoulda (3.0.1)
|
26
|
+
shoulda-context (~> 1.0.0)
|
27
|
+
shoulda-matchers (~> 1.0.0)
|
28
|
+
shoulda-context (1.0.0)
|
29
|
+
shoulda-matchers (1.0.0)
|
30
|
+
simplecov (0.6.1)
|
31
|
+
multi_json (~> 1.0)
|
32
|
+
simplecov-html (~> 0.5.3)
|
33
|
+
simplecov-html (0.5.3)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.1.0)
|
40
|
+
choice (~> 0.1.6)
|
41
|
+
jeweler (~> 1.8.3)
|
42
|
+
rdoc (~> 3.12)
|
43
|
+
selenium-webdriver (~> 2.20)
|
44
|
+
shoulda
|
45
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Adnan Abdulhussein
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= pictate
|
2
|
+
|
3
|
+
Pictate is a pointless command line tool that attempts to describe a picture
|
4
|
+
you give it. Or rather, Google search by image does. I created it because this
|
5
|
+
was funkier as a first gem than the boring traditional "Hello World!".
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
$ pictate /path/to/image [options]
|
9
|
+
|
10
|
+
== Selenium
|
11
|
+
|
12
|
+
Unfortunately Google uses a lot of Javascript and as such this gem uses browser
|
13
|
+
automation in the form of Selenium[http://seleniumhq.org/projects/webdriver/]
|
14
|
+
to fetch the result. You may specify a path to the server, or it'll be
|
15
|
+
downloaded and stored in the _ext_ directory of the gem.
|
16
|
+
|
17
|
+
To specify the server:
|
18
|
+
$ pictate /path/to/image -s /path/to/server/jar
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "pictate"
|
18
|
+
gem.homepage = "http://github.com/Prydonius/pictate"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Attempts to describe a picture you give it.}
|
21
|
+
gem.description = %Q{Pointless command line tool that attempts to describe the image you give it by automating a google search by image.}
|
22
|
+
gem.email = "adnan@prydoni.us"
|
23
|
+
gem.authors = ["Adnan Abdulhussein"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "pictate #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
rdoc.main = "README.rdoc"
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/bin/pictate
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'choice'
|
5
|
+
require 'pictate'
|
6
|
+
|
7
|
+
include Pictate
|
8
|
+
|
9
|
+
#
|
10
|
+
# Command line parsing
|
11
|
+
#
|
12
|
+
Choice.options do
|
13
|
+
banner "Usage: <image> [options]"
|
14
|
+
option :server do
|
15
|
+
long "--server=SERVER"
|
16
|
+
short "-s"
|
17
|
+
desc "Location of selenium standalone server jar"
|
18
|
+
desc "If this isn't specified, the latest server will be downloaded " +
|
19
|
+
"and used."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Print error and help message, then exit
|
25
|
+
#
|
26
|
+
def show_error str="There was an error with the parsing..."
|
27
|
+
puts str
|
28
|
+
Choice.help
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Check image extension
|
34
|
+
#
|
35
|
+
ext = File.extname Choice.rest.first || ""
|
36
|
+
if not %w[.jpg .png .gif .bmp].include? ext
|
37
|
+
show_error "Please pass in the path of an image with one of the " +
|
38
|
+
"following extensions:\n.jpg, .png, .gif, or .bmp\n\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Check if standalone server extension is .jar
|
43
|
+
#
|
44
|
+
if Choice.choices[:server]
|
45
|
+
if not (File.extname Choice.choices[:server]) == ".jar"
|
46
|
+
show_error "Please specify the path of the jar standalone selenium " +
|
47
|
+
"server.\n\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Pictate.pictate Choice.rest.first, Choice.choices
|
data/ext/.gitignore
ADDED
File without changes
|
data/lib/pictate.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require "selenium-webdriver"
|
2
|
+
require "selenium/server"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
PICTATE_ROOT = Gem.loaded_specs['pictate'].full_gem_path
|
6
|
+
|
7
|
+
module Pictate
|
8
|
+
#
|
9
|
+
# Starts the server, gets the best result for the image and stops server.
|
10
|
+
#
|
11
|
+
def pictate(image_path, options = {})
|
12
|
+
start_server options[:server]
|
13
|
+
puts "I'm thinking..."
|
14
|
+
puts do_search image_path
|
15
|
+
stop_server
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Starts the server.
|
20
|
+
# Checks to see if you've given it a server path, if not it will check the
|
21
|
+
# _ext_ directory of the gem library. If it's not there, it will download it
|
22
|
+
# to that directory.
|
23
|
+
# Note:: perhaps a better directory is needed as it is overwritten when the
|
24
|
+
# gem is reinstalled.
|
25
|
+
#
|
26
|
+
def start_server(server_path)
|
27
|
+
if server_path
|
28
|
+
selenium_path = server_path
|
29
|
+
else
|
30
|
+
previous_wd = FileUtils.pwd
|
31
|
+
FileUtils.cd(File.join PICTATE_ROOT, 'ext')
|
32
|
+
selenium_latest = Selenium::Server.latest
|
33
|
+
if not File.exists? "selenium-server-standalone-#{selenium_latest}.jar"
|
34
|
+
puts "Downloading latest version of selenium server standalone..."
|
35
|
+
end
|
36
|
+
selenium_path = Selenium::Server.download(selenium_latest)
|
37
|
+
end
|
38
|
+
|
39
|
+
puts "Starting selenium standalone server"
|
40
|
+
@server = Selenium::Server.new(selenium_path, :background => true)
|
41
|
+
@server.start
|
42
|
+
caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(
|
43
|
+
:javascript_enabled => true)
|
44
|
+
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps)
|
45
|
+
FileUtils.cd(previous_wd)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Stops the server
|
50
|
+
#
|
51
|
+
def stop_server
|
52
|
+
puts "Stopping server..."
|
53
|
+
@driver.quit
|
54
|
+
@server.stop
|
55
|
+
puts "Goodbye!"
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Carries out the search and retrieves the best match
|
60
|
+
#
|
61
|
+
def do_search(image_path)
|
62
|
+
@driver.navigate.to "http://www.google.co.uk/searchbyimage"
|
63
|
+
# show the upload dialog
|
64
|
+
@driver.execute_script("google.qb.ti(true)")
|
65
|
+
|
66
|
+
# upload image and search
|
67
|
+
upload = @driver.find_element(:name, 'encoded_image')
|
68
|
+
upload.send_keys(File.expand_path image_path)
|
69
|
+
|
70
|
+
# best result
|
71
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => 100)
|
72
|
+
wait.until { @driver.find_element(:id => 'topstuff') }
|
73
|
+
topstuff = @driver.find_element(:id => 'topstuff')
|
74
|
+
best = topstuff.text.lines.to_a.last
|
75
|
+
if not best.match /Best(.*)/
|
76
|
+
result = "Can't figure it out for the life of me, sorry!"
|
77
|
+
else
|
78
|
+
best.gsub!("Best guess for this image:", "")
|
79
|
+
result = "I believe this is a picture of: #{best}."
|
80
|
+
end
|
81
|
+
result
|
82
|
+
end
|
83
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'pictate'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pictate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adnan Abdulhussein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: &70316967178900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70316967178900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &70316967193940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.12'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70316967193940
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &70316967193140 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70316967193140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &70316967192420 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.3
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70316967192420
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &70316967191780 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70316967191780
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: selenium-webdriver
|
71
|
+
requirement: &70316967190580 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.20'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70316967190580
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: choice
|
82
|
+
requirement: &70316967189100 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.1.6
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70316967189100
|
91
|
+
description: Pointless command line tool that attempts to describe the image you give
|
92
|
+
it by automating a google search by image.
|
93
|
+
email: adnan@prydoni.us
|
94
|
+
executables:
|
95
|
+
- pictate
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files:
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.rdoc
|
100
|
+
files:
|
101
|
+
- .document
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.rdoc
|
106
|
+
- Rakefile
|
107
|
+
- VERSION
|
108
|
+
- bin/pictate
|
109
|
+
- ext/.gitignore
|
110
|
+
- lib/pictate.rb
|
111
|
+
- test/helper.rb
|
112
|
+
- test/test_pictate.rb
|
113
|
+
homepage: http://github.com/Prydonius/pictate
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: -908780192612818260
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.8.11
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: Attempts to describe a picture you give it.
|
141
|
+
test_files: []
|