staker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +22 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/staker.rb +115 -0
- data/lib/staker/stak_over_flow.rb +109 -0
- data/lib/staker/version.rb +3 -0
- data/staker.gemspec +37 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e78d25e478b711f597acb61b87d02ac2de7f67f2
|
4
|
+
data.tar.gz: d3a0380661307cc5ce1f6f27091ce5c02d4635f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1fd07793e1c28aba846a0664edf9469e73b0b6bdaa3f778fe8574c9b16c1831bd8ff7eb2ce71917160f0706ae5c8a9ee109681212f7193d1368d0b4f9399ad5
|
7
|
+
data.tar.gz: f3ccb630b288c373be2f649c8b3ce39ab1c7609721c8cb568932372597a39c108d06b3bc231eece11394d76acfa18e41fa04eb17cfae62e4158b6a4c38388849
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 santhums
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Staker
|
2
|
+
|
3
|
+
Staker is helper class for searching over stalkoverflow.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'staker'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install staker
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
Staker.lookup("customise devise in rails")
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "staker"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/staker.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require "staker/version"
|
2
|
+
require "staker/stak_over_flow"
|
3
|
+
# require_relative 'lib/staker/stak_over_flow'
|
4
|
+
# require 'open-uri'
|
5
|
+
# require 'nokogiri'
|
6
|
+
# require 'launchy'
|
7
|
+
|
8
|
+
module Staker
|
9
|
+
def self.lookup(query)
|
10
|
+
StakOverFlow.new.query(query)
|
11
|
+
# Staker::VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# class StakOverFlow
|
16
|
+
|
17
|
+
# BASE_URL = "http://stackoverflow.com"
|
18
|
+
# SEARCH_URL = "#{BASE_URL}/search?q="
|
19
|
+
# SEARCH_LIMIT = 5
|
20
|
+
# def initialize
|
21
|
+
# end
|
22
|
+
|
23
|
+
# def query(q)
|
24
|
+
# query_url = SEARCH_URL + q.split.join('+')
|
25
|
+
# begin
|
26
|
+
# page = Nokogiri::HTML(open(query_url))
|
27
|
+
# @results = page.css('.result-link a')
|
28
|
+
# rescue => e
|
29
|
+
# puts "*" * 20
|
30
|
+
# puts e.message
|
31
|
+
# puts "*" * 20
|
32
|
+
# return false
|
33
|
+
# end
|
34
|
+
|
35
|
+
# get_links
|
36
|
+
|
37
|
+
# result = get_ansewers.to_s
|
38
|
+
|
39
|
+
# HtmlResponse.new(result)
|
40
|
+
# end
|
41
|
+
|
42
|
+
# def get_links
|
43
|
+
# @result_links = []
|
44
|
+
# @results.each do |link|
|
45
|
+
# @result_links << BASE_URL + link.attributes['href'].value
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
|
49
|
+
# def get_ansewers
|
50
|
+
# begin
|
51
|
+
# answers = []
|
52
|
+
# @result_links[0..SEARCH_LIMIT-1].each do |r_links|
|
53
|
+
# doc = Nokogiri::HTML(open(r_links))
|
54
|
+
# ans = doc.css('div.accepted-answer td.answercell div.post-text').to_s
|
55
|
+
# qstn = doc.css('#question-header .question-hyperlink')[0]
|
56
|
+
# qstn.attributes['href'].value = BASE_URL + qstn.attributes['href'].value
|
57
|
+
# unless ans.empty?
|
58
|
+
# answers << qstn.to_s + ans
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# final_answers = answers.join('<hr>')
|
62
|
+
# rescue => e
|
63
|
+
# puts "*" * 20
|
64
|
+
# puts e.message
|
65
|
+
# puts "*" * 20
|
66
|
+
# return false
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
|
71
|
+
# class HtmlResponse
|
72
|
+
# GEM_TITLE = "Stalker"
|
73
|
+
# TEMPLATE_ONE = "<html><head><title>Stalker</title>
|
74
|
+
# <style>
|
75
|
+
# pre {
|
76
|
+
# overflow: auto;
|
77
|
+
# font-size: 13px;
|
78
|
+
# padding: 5px;
|
79
|
+
# width: 800px;
|
80
|
+
# width: 650px !ie7;
|
81
|
+
# padding-bottom: 20px !ie7;
|
82
|
+
# max-height: 600px;
|
83
|
+
# background-color: #eee;
|
84
|
+
# margin-bottom: 1em;
|
85
|
+
# font-family: Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,sans-serif;
|
86
|
+
# }
|
87
|
+
# p, pre {
|
88
|
+
# width: 800px;
|
89
|
+
# font-size: 18px;
|
90
|
+
# }
|
91
|
+
# </style>
|
92
|
+
# </head><body><h1>#{GEM_TITLE}</h1><h3>Result On : #{}</h3>"
|
93
|
+
|
94
|
+
# TEMPLATE_TWO = "</body></html>"
|
95
|
+
|
96
|
+
# def initialize(response)
|
97
|
+
# html_body = TEMPLATE_ONE + response + TEMPLATE_TWO
|
98
|
+
# # TODO:: Create file inside tmp
|
99
|
+
# out_file = File.new("staker_out.html", "w")
|
100
|
+
# out_file.puts(html_body)
|
101
|
+
# out_file.close
|
102
|
+
# Launchy.open(Dir.pwd + "/staker_out.html")
|
103
|
+
# end
|
104
|
+
|
105
|
+
# def method_name
|
106
|
+
# # html_body = TEMPLATE_ONE + final_ans.to_s + TEMPLATE_TWO
|
107
|
+
# # # TODO:: Create file inside tmp
|
108
|
+
# # out_file = File.new("staker_out.html", "w")
|
109
|
+
# # out_file.puts(html)
|
110
|
+
# # out_file.close
|
111
|
+
# # Launchy.open(Dir.pwd + "/staker_out.html")
|
112
|
+
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'launchy'
|
4
|
+
|
5
|
+
module Staker
|
6
|
+
|
7
|
+
class StakOverFlow
|
8
|
+
|
9
|
+
BASE_URL = "http://stackoverflow.com"
|
10
|
+
SEARCH_URL = "#{BASE_URL}/search?q="
|
11
|
+
SEARCH_LIMIT = 2
|
12
|
+
def initialize
|
13
|
+
end
|
14
|
+
|
15
|
+
def query(q)
|
16
|
+
query_url = SEARCH_URL + q.split.join('+')
|
17
|
+
begin
|
18
|
+
page = Nokogiri::HTML(open(query_url))
|
19
|
+
@results = page.css('.result-link a')
|
20
|
+
rescue => e
|
21
|
+
puts "*" * 20
|
22
|
+
puts e.message
|
23
|
+
puts "*" * 20
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
|
27
|
+
get_links
|
28
|
+
|
29
|
+
result = get_ansewers.to_s
|
30
|
+
|
31
|
+
HtmlResponse.new(result)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_links
|
35
|
+
@result_links = []
|
36
|
+
@results.each do |link|
|
37
|
+
@result_links << BASE_URL + link.attributes['href'].value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_ansewers
|
42
|
+
begin
|
43
|
+
answers = []
|
44
|
+
@result_links[0..SEARCH_LIMIT-1].each do |r_links|
|
45
|
+
doc = Nokogiri::HTML(open(r_links))
|
46
|
+
ans = doc.css('div.accepted-answer td.answercell div.post-text').to_s
|
47
|
+
qstn = doc.css('#question-header .question-hyperlink')[0]
|
48
|
+
qstn.attributes['href'].value = BASE_URL + qstn.attributes['href'].value
|
49
|
+
unless ans.empty?
|
50
|
+
answers << qstn.to_s + ans
|
51
|
+
end
|
52
|
+
end
|
53
|
+
final_answers = answers.join('<hr>')
|
54
|
+
rescue => e
|
55
|
+
puts "*" * 20
|
56
|
+
puts e.message
|
57
|
+
puts "*" * 20
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class HtmlResponse
|
64
|
+
GEM_TITLE = "Stalker"
|
65
|
+
TEMPLATE_ONE = "<html><head><title>Stalker</title>
|
66
|
+
<style>
|
67
|
+
pre {
|
68
|
+
overflow: auto;
|
69
|
+
font-size: 13px;
|
70
|
+
padding: 5px;
|
71
|
+
width: 800px;
|
72
|
+
width: 650px !ie7;
|
73
|
+
padding-bottom: 20px !ie7;
|
74
|
+
max-height: 600px;
|
75
|
+
background-color: #eee;
|
76
|
+
margin-bottom: 1em;
|
77
|
+
font-family: Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,sans-serif;
|
78
|
+
}
|
79
|
+
p, pre {
|
80
|
+
width: 800px;
|
81
|
+
font-size: 18px;
|
82
|
+
}
|
83
|
+
</style>
|
84
|
+
</head><body><h1>#{GEM_TITLE}</h1><h3>Result On : #{}</h3>"
|
85
|
+
|
86
|
+
TEMPLATE_TWO = "</body></html>"
|
87
|
+
|
88
|
+
def initialize(response)
|
89
|
+
html_body = TEMPLATE_ONE + response + TEMPLATE_TWO
|
90
|
+
# TODO:: Create file inside tmp
|
91
|
+
out_file = File.new("staker_out.html", "w")
|
92
|
+
out_file.puts(html_body)
|
93
|
+
out_file.close
|
94
|
+
Launchy.open(Dir.pwd + "/staker_out.html")
|
95
|
+
end
|
96
|
+
|
97
|
+
def method_name
|
98
|
+
# html_body = TEMPLATE_ONE + final_ans.to_s + TEMPLATE_TWO
|
99
|
+
# # TODO:: Create file inside tmp
|
100
|
+
# out_file = File.new("staker_out.html", "w")
|
101
|
+
# out_file.puts(html)
|
102
|
+
# out_file.close
|
103
|
+
# Launchy.open(Dir.pwd + "/staker_out.html")
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
data/staker.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
# lib = File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
# $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'staker/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "staker"
|
10
|
+
spec.version = Staker::VERSION
|
11
|
+
spec.authors = ["santhums"]
|
12
|
+
spec.email = ["santhu@7nodes.com"]
|
13
|
+
|
14
|
+
# if spec.respond_to?(:metadata)
|
15
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
16
|
+
# end
|
17
|
+
|
18
|
+
spec.summary = %q{Staker is helper class for searching over stalkoverflow.}
|
19
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
20
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
21
|
+
spec.license = "MIT"
|
22
|
+
|
23
|
+
spec.files = [".gitignore", "CODE_OF_CONDUCT.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "lib/staker.rb", "lib/staker/version.rb", "staker.gemspec", "lib/staker/stak_over_flow.rb"]
|
24
|
+
# spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }.push("lib/staker/stak_over_flow.rb")
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency 'nokogiri'
|
30
|
+
spec.add_dependency 'launchy'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency 'rspec'
|
35
|
+
|
36
|
+
# spec.add_runtime_dependency 'savon'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: staker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- santhums
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
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: launchy
|
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.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.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
|
+
description:
|
84
|
+
email:
|
85
|
+
- santhu@7nodes.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- CODE_OF_CONDUCT.md
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/staker.rb
|
99
|
+
- lib/staker/stak_over_flow.rb
|
100
|
+
- lib/staker/version.rb
|
101
|
+
- staker.gemspec
|
102
|
+
homepage:
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Staker is helper class for searching over stalkoverflow.
|
126
|
+
test_files: []
|