google_search_criterion 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/bin/google-results +9 -0
- data/google_search_criterion.gemspec +29 -0
- data/lib/google_search_criterion.rb +6 -0
- data/lib/google_search_criterion/cli.rb +28 -0
- data/lib/google_search_criterion/search.rb +40 -0
- data/lib/google_search_criterion/version.rb +3 -0
- data/spec/lib/google_search_criterion/results_spec.rb +32 -0
- data/spec/spec_helper.rb +21 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e0d3dcbadb27777135780059dfe46a8e64acce97
|
4
|
+
data.tar.gz: 036ee74ac328f94c6eddb654714b4b29cc9697ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0aff8a9e24602ce6f19d5ffab19e4b663d86829f4f4407cdf4d9b214d77c929ac7e73903aa26251bec26e1663f9ed57554574e6cad24028931453bf28fa246bd
|
7
|
+
data.tar.gz: 19dd946ef3251cce6d552bd6ea9ea26355698808f032b01b01da981598cc75c4994233d0e844b8e14e4b5f937d5075388d4d1057908d556ec8fed8b9bd378d92
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Giorgos Tsiftsis
|
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,58 @@
|
|
1
|
+
# GoogleSearchCriterion
|
2
|
+
|
3
|
+
A toy to compare words against Google search results. Language is a vivid
|
4
|
+
organism. There is no right or wrong. By observing results from Google one can
|
5
|
+
observe the usage of words and compare them with others. All explanations
|
6
|
+
should be avoided :)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'google_search_criterion'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install google_search_criterion
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Type ```$ google-results``` for help.
|
25
|
+
|
26
|
+
1. Examine names popularity
|
27
|
+
|
28
|
+
In Greece - like everywhere else - we have a couple of very popular first names
|
29
|
+
for men like γιωργος γιαννης κωστας . I believe that γιαννης is more popular
|
30
|
+
than γιωργος and κωστας is in the third place. I can easily investigate my
|
31
|
+
assumption:
|
32
|
+
|
33
|
+
```
|
34
|
+
$ google-results sort γιαννης γιωργος κωστας
|
35
|
+
```
|
36
|
+
|
37
|
+
2. Examine preferred form of a word
|
38
|
+
|
39
|
+
I want to write αχιλεας but I am not sure if it is written with one 'λ' or
|
40
|
+
2 'λ's or one 'χ'
|
41
|
+
|
42
|
+
```
|
43
|
+
$ google-results sort αχιλεας αχχιλεας αχιλλεας αχχιλλεας
|
44
|
+
```
|
45
|
+
|
46
|
+
3. I want to see what is the most popular polital party
|
47
|
+
|
48
|
+
```
|
49
|
+
$ google-results sort "νεα δημοκρατια" πασοκ κκε συριζα ανελ
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it ( http://github.com/<my-github-username>/google_search_criterion/fork )
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/google-results
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'google_search_criterion/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "google_search_criterion"
|
9
|
+
spec.version = GoogleSearchCriterion::VERSION
|
10
|
+
spec.authors = ["Giorgos Tsiftsis"]
|
11
|
+
spec.email = ["giorgos.tsiftsis@skroutz.gr"]
|
12
|
+
spec.summary = %q{ A toy to compare words against google search results }
|
13
|
+
spec.description = %q{ A toy to compare words against google search results }
|
14
|
+
spec.homepage = "https://github.com/chief/google_search_criterion"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "mechanize"
|
23
|
+
spec.add_dependency "thor"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "pry-byebug"
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module GoogleSearchCriterion
|
4
|
+
class CLI < Thor
|
5
|
+
|
6
|
+
desc "sort KEYPHRASES",
|
7
|
+
"sort KEYPHRASES by Google search results count"
|
8
|
+
def sort(*keyphrases)
|
9
|
+
keyphrases.map! do |keyphrase|
|
10
|
+
{ keyphrase: keyphrase,
|
11
|
+
results: GoogleSearchCriterion::Search.results(keyphrase) }
|
12
|
+
end.sort! { |x, y| y[:results] <=> x[:results] }
|
13
|
+
|
14
|
+
keyphrases.each do |keyphrase|
|
15
|
+
puts "#{keyphrase[:keyphrase]} => #{keyphrase[:results]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "get KEYPHRASES", "gets results from Google for KEYPHRASES"
|
20
|
+
def get(*keyphrases)
|
21
|
+
puts "Nothing to show" if keyphrases.empty?
|
22
|
+
|
23
|
+
keyphrases.each do |keyphrase|
|
24
|
+
puts "#{keyphrase} => #{GoogleSearchCriterion::Search.results(keyphrase)}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "mechanize"
|
2
|
+
|
3
|
+
module GoogleSearchCriterion
|
4
|
+
module Search
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def results(keyphrase)
|
8
|
+
result_stats = scrape_result_stats(keyphrase)
|
9
|
+
tokens = result_stats.split(' ')
|
10
|
+
|
11
|
+
case tokens.first
|
12
|
+
when "About"
|
13
|
+
tokens[1]
|
14
|
+
else
|
15
|
+
tokens.first
|
16
|
+
end.to_s.gsub(",","").to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def scrape_result_stats(keyphrase)
|
22
|
+
results = nil
|
23
|
+
|
24
|
+
agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
|
25
|
+
|
26
|
+
agent.get('http://google.com/en') do |page|
|
27
|
+
search_result = page.form_with(:name => 'gbqf') do |search|
|
28
|
+
search.q = keyphrase
|
29
|
+
|
30
|
+
# Avoid google spell checking
|
31
|
+
search.add_field! "nfpr", "1"
|
32
|
+
end.submit
|
33
|
+
|
34
|
+
results = search_result.search("div#resultStats").text
|
35
|
+
end
|
36
|
+
|
37
|
+
results
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GoogleSearchCriterion::Search do
|
4
|
+
describe ".results" do
|
5
|
+
it "gets the results from www.google.com for a given keyphrase" do
|
6
|
+
expect(described_class.results("ruby rocks")).to be > 0
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when there are no results" do
|
10
|
+
it "returns 0" do
|
11
|
+
expect(described_class.
|
12
|
+
results("4#@@@@3fefe09-this-should-provide-012121-αποτελέσματα")).to eq(0)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when there are few results" do
|
17
|
+
it "gets the result" do
|
18
|
+
expect(described_class.
|
19
|
+
results("αυτό είναι result ασκαρδαμικτι περσεφονη")).to be < 100
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not apply auto-complete" do
|
24
|
+
expect(described_class.results("κωραης")).not_to eq(
|
25
|
+
described_class.results("κοραης"))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "transforms numbers correctly" do
|
29
|
+
expect(described_class.results("κάτοικος")).to be > 1_000
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require "google_search_criterion"
|
9
|
+
require "pry"
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_search_criterion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giorgos Tsiftsis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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: rspec
|
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: pry-byebug
|
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
|
+
description: " A toy to compare words against google search results "
|
98
|
+
email:
|
99
|
+
- giorgos.tsiftsis@skroutz.gr
|
100
|
+
executables:
|
101
|
+
- google-results
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/google-results
|
112
|
+
- google_search_criterion.gemspec
|
113
|
+
- lib/google_search_criterion.rb
|
114
|
+
- lib/google_search_criterion/cli.rb
|
115
|
+
- lib/google_search_criterion/search.rb
|
116
|
+
- lib/google_search_criterion/version.rb
|
117
|
+
- spec/lib/google_search_criterion/results_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: https://github.com/chief/google_search_criterion
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.0
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A toy to compare words against google search results
|
143
|
+
test_files:
|
144
|
+
- spec/lib/google_search_criterion/results_spec.rb
|
145
|
+
- spec/spec_helper.rb
|