quora-webdriver 0.1.0
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 +14 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/lib/quora-webdriver.rb +7 -0
- data/lib/quora-webdriver/browser.rb +7 -0
- data/lib/quora-webdriver/quora.rb +115 -0
- data/lib/quora-webdriver/version.rb +7 -0
- data/quora-webdriver.gemspec +28 -0
- data/spec/quora_spec.rb +5 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4ba97b73dcd575196ceb622bb13ec6437928a93
|
4
|
+
data.tar.gz: b44de6639dffddfe14802de2bd9a66ebda977e74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a2afc9cc7d7d3d62ef9211a4c66f939abf0b08eb977504cd40384771e0ba190bd3230a2e149f99fde288a0340169aa3bd8095cde4bd0dc67aa1b9d47255bfe2
|
7
|
+
data.tar.gz: 1357c859d16217a3de472de301f532fd44ed99f7a7bdc923967213dc763e029240855dab429757fb20911db82171b7a03350fa3f1bc27eeb5fe88d6615e683ec
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Giordon Stark
|
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,31 @@
|
|
1
|
+
# Watir::Browser::Quora
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'quora-webdriver'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install quora-webdriver
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/quora-webdriver/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module Watir
|
2
|
+
class Browser
|
3
|
+
class Quora
|
4
|
+
|
5
|
+
attr_reader :base_url, :url
|
6
|
+
attr_accessor :user
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(browser)
|
10
|
+
@browser = browser
|
11
|
+
@base_url = "https://www.quora.com/"
|
12
|
+
@logged_in = false
|
13
|
+
@email_box_selector = {:name=>"email", :class=>/header_login_text_box/}
|
14
|
+
@password_box_selector = {:name=>"password", :class=>/header_login_text_box/}
|
15
|
+
@login_button_selector = {:value=>"Login"}
|
16
|
+
@add_question_selector = {:class=>/inner/, :text=>/Add Question/}
|
17
|
+
end
|
18
|
+
|
19
|
+
def user
|
20
|
+
@user ||= :Giordon_Stark
|
21
|
+
end
|
22
|
+
|
23
|
+
def stringify
|
24
|
+
@user.to_s.gsub("_","-")
|
25
|
+
end
|
26
|
+
|
27
|
+
def login(choice='0')
|
28
|
+
return @logged_in if @logged_in
|
29
|
+
until ['1', '2'].include?(choice)
|
30
|
+
puts "This page requires a login.\n\t(1) Login via browser\n\t(2) Login via command line"
|
31
|
+
choice = gets.chomp
|
32
|
+
end
|
33
|
+
case choice
|
34
|
+
when '1'
|
35
|
+
puts "Please navigate to the browser and login."
|
36
|
+
when '2'
|
37
|
+
email = ask("Enter email: "){ |x| x.echo = true }
|
38
|
+
password = ask("Enter password: "){ |x| x.echo = "*" }
|
39
|
+
email_box = @browser.text_field(@email_box_selector)
|
40
|
+
password_box = @browser.text_field(@password_box_selector)
|
41
|
+
unless email_box.exist? and password_box.exist? then
|
42
|
+
puts "There was an error getting the login boxes. Please login manually. Report this error to someone important."
|
43
|
+
self.login('1')
|
44
|
+
end
|
45
|
+
email_box.set email
|
46
|
+
password_box.set password
|
47
|
+
@browser.button(@login_button_selector).click
|
48
|
+
end
|
49
|
+
|
50
|
+
self.verify_login
|
51
|
+
end
|
52
|
+
|
53
|
+
def verify_login
|
54
|
+
# check every 6 seconds for 1 minute
|
55
|
+
login_count_checks = 0
|
56
|
+
until @logged_in || (login_count_checks >= 60) do
|
57
|
+
puts "\t Checking if logged in"
|
58
|
+
@logged_in = @browser.div(@add_question_selector).exists?
|
59
|
+
login_count_checks+=1
|
60
|
+
sleep 1
|
61
|
+
end
|
62
|
+
|
63
|
+
if @logged_in then
|
64
|
+
puts "Successfully logged in!"
|
65
|
+
elsif @browser.text_field(:name=> "email", :class=>/header_login_text_box/).exist? then
|
66
|
+
puts "There was an error logging in. Most likely a wrong username or password."
|
67
|
+
else
|
68
|
+
puts "There was an error logging in."
|
69
|
+
end
|
70
|
+
self.login
|
71
|
+
end
|
72
|
+
|
73
|
+
def goto(login = nil)
|
74
|
+
@browser.goto "#{@url}#{login.nil? ? '?share=1' : ''}"
|
75
|
+
unless login.nil? then
|
76
|
+
self.login
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def answers
|
81
|
+
@url = "#{@base_url}#{self.stringify}/answers?share=1"
|
82
|
+
self.goto
|
83
|
+
end
|
84
|
+
|
85
|
+
def content(subcategory = :all)
|
86
|
+
case subcategory
|
87
|
+
when :questions_added,
|
88
|
+
:questions_followed,
|
89
|
+
:answers,
|
90
|
+
:posts
|
91
|
+
@url = "#{@base_url}content?content_types=#{subcategory}"
|
92
|
+
else
|
93
|
+
@url = "#{@base_url}content"
|
94
|
+
end
|
95
|
+
self.goto :login
|
96
|
+
end
|
97
|
+
|
98
|
+
def scroll_n_times(n = 1)
|
99
|
+
n.times do
|
100
|
+
@browser.scroll.to :bottom
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_all
|
105
|
+
last_size = 0
|
106
|
+
while last_size != self.html.size do
|
107
|
+
last_size = self.html.size
|
108
|
+
@browser.scroll.to :bottom
|
109
|
+
# sleep for 3 seconds to handle ajax request delay until page updates
|
110
|
+
sleep 3
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quora-webdriver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quora-webdriver"
|
8
|
+
spec.version = Watir::Browser::Quora::VERSION
|
9
|
+
spec.authors = ["Giordon Stark"]
|
10
|
+
spec.email = ["kratsg@gmail.com"]
|
11
|
+
spec.summary = %q{Interact with Quora via Command Line}
|
12
|
+
spec.description = %q{Interact with Quora via Command Line.}
|
13
|
+
spec.homepage = "https://github.com/kratsg/quora-webdriver"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "watir-webdriver", "~> 0.6"
|
22
|
+
spec.add_dependency "watir-scroll", "~> 0.1"
|
23
|
+
spec.add_dependency "highline", "~> 1.6"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
28
|
+
end
|
data/spec/quora_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quora-webdriver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giordon Stark
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: watir-webdriver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: watir-scroll
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.1'
|
97
|
+
description: Interact with Quora via Command Line.
|
98
|
+
email:
|
99
|
+
- kratsg@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/quora-webdriver.rb
|
111
|
+
- lib/quora-webdriver/browser.rb
|
112
|
+
- lib/quora-webdriver/quora.rb
|
113
|
+
- lib/quora-webdriver/version.rb
|
114
|
+
- quora-webdriver.gemspec
|
115
|
+
- spec/quora_spec.rb
|
116
|
+
homepage: https://github.com/kratsg/quora-webdriver
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.4
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Interact with Quora via Command Line
|
140
|
+
test_files:
|
141
|
+
- spec/quora_spec.rb
|