quora-webdriver 0.1.2 → 0.1.3
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 +4 -4
- data/Gemfile +0 -1
- data/README.md +10 -3
- data/lib/quora-webdriver.rb +4 -1
- data/lib/quora-webdriver/base.rb +19 -0
- data/lib/quora-webdriver/quora.rb +100 -103
- data/lib/quora-webdriver/stats.rb +19 -0
- data/lib/quora-webdriver/version.rb +3 -7
- data/quora-webdriver.gemspec +1 -1
- metadata +4 -3
- data/lib/quora-webdriver/browser.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1885e29e7a94a6d00091e63177477f2000ea6473
|
4
|
+
data.tar.gz: ead5b8b14df5bf33c38856b4c747b08c5c6545c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc56debc048690248ae6c55cfd146fc74a1bea8a157c819a89d53d0eea4e895d20e122f88630f0307c82d5456149f5135d4a0fae372c75629cd486005cf7412d
|
7
|
+
data.tar.gz: 5182d4478cf857d8e6c0a2ffd18cd1d2314534f9c68a70e9556a03da5afaa333469df7da9c67f37dd4da61468c2accabf9302517e9c5afaea5e9ca2dcf544d8a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,13 @@ There are not a lot of features added yet. This is to get started and I welcome
|
|
38
38
|
|
39
39
|
1. Fork it ( https://github.com/kratsg/quora-webdriver/fork )
|
40
40
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
-
3.
|
42
|
-
4.
|
43
|
-
5.
|
41
|
+
3. **Write your tests!**
|
42
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
6. Create a new Pull Request
|
45
|
+
|
46
|
+
### Issue
|
47
|
+
|
48
|
+
Pull requests from forks will most likely have builds that fail because of private keys being used for OpenSauce. Please commit with a message that includes `[skip ci]` and I'll checkout and push myself to see if the pull request passes build before merging. This message should tell Travis to skip the build. More information
|
49
|
+
- http://docs.travis-ci.com/user/pull-requests/
|
50
|
+
- https://github.com/travis-ci/travis-ci/issues/1946
|
data/lib/quora-webdriver.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Watir
|
2
|
+
class Browser
|
3
|
+
|
4
|
+
attr_reader :quora
|
5
|
+
def quora
|
6
|
+
@Quora ||= Quora.new(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Quora
|
10
|
+
include QuoraWebDriver::QuoraModule
|
11
|
+
|
12
|
+
attr_reader :stats
|
13
|
+
def stats
|
14
|
+
@Stats ||= Stats.new(self)
|
15
|
+
end
|
16
|
+
end # Quora
|
17
|
+
|
18
|
+
end # Browser
|
19
|
+
end # Watir
|
@@ -1,131 +1,128 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
1
|
+
module QuoraWebDriver
|
2
|
+
module QuoraModule
|
3
|
+
attr_reader :base_url, :url
|
4
|
+
attr_accessor :user
|
4
5
|
|
5
|
-
attr_reader :base_url, :url
|
6
|
-
attr_accessor :user
|
7
6
|
|
7
|
+
def initialize(browser)
|
8
|
+
@browser = browser
|
9
|
+
@base_url = "https://www.quora.com/"
|
10
|
+
@logged_in = false
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@logged_in = false
|
13
|
-
end
|
13
|
+
def user
|
14
|
+
@user ||= :Giordon_Stark
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
def stringify
|
18
|
+
@user.to_s.gsub("_","-")
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
def get_login_email_text
|
22
|
+
@browser.text_field({:name=>"email", :class=>/header_login_text_box/})
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
def get_login_password_text
|
26
|
+
@browser.text_field({:name=>"password", :class=>/header_login_text_box/})
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
def get_login_submit_button
|
30
|
+
@browser.button({:value=>"Login"})
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
def get_add_question_div
|
34
|
+
@browser.div({:class=>/inner/, :text=>/Add Question/})
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
def login(choice='0')
|
38
|
+
return @logged_in if @logged_in
|
39
|
+
until ['1', '2'].include?(choice)
|
40
|
+
puts "This page requires a login.\n\t(1) Login via browser\n\t(2) Login via command line"
|
41
|
+
choice = gets.chomp
|
37
42
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
puts "
|
48
|
-
|
49
|
-
email = ask("Enter email: "){ |x| x.echo = true }
|
50
|
-
password = ask("Enter password: "){ |x| x.echo = "*" }
|
51
|
-
email_box = get_login_email_text
|
52
|
-
password_box = get_login_password_text
|
53
|
-
unless email_box.exist? and password_box.exist? then
|
54
|
-
puts "There was an error getting the login boxes. Please login manually. Report this error to someone important."
|
55
|
-
self.login('1')
|
56
|
-
end
|
57
|
-
email_box.set email
|
58
|
-
password_box.set password
|
59
|
-
get_login_submit_button.click
|
43
|
+
case choice
|
44
|
+
when '1'
|
45
|
+
puts "Please navigate to the browser and login."
|
46
|
+
when '2'
|
47
|
+
email = ask("Enter email: "){ |x| x.echo = true }
|
48
|
+
password = ask("Enter password: "){ |x| x.echo = "*" }
|
49
|
+
email_box = get_login_email_text
|
50
|
+
password_box = get_login_password_text
|
51
|
+
unless email_box.exist? and password_box.exist? then
|
52
|
+
puts "There was an error getting the login boxes. Please login manually. Report this error to someone important."
|
53
|
+
self.login('1')
|
60
54
|
end
|
61
|
-
|
62
|
-
|
55
|
+
email_box.set email
|
56
|
+
password_box.set password
|
57
|
+
get_login_submit_button.click
|
63
58
|
end
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
login_count_checks = 0
|
68
|
-
until @logged_in || (login_count_checks >= 60) do
|
69
|
-
puts "\t Checking if logged in"
|
70
|
-
@logged_in = get_add_question_div.exists?
|
71
|
-
login_count_checks+=1
|
72
|
-
sleep 1
|
73
|
-
end
|
60
|
+
self.verify_login
|
61
|
+
end
|
74
62
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
63
|
+
def verify_login
|
64
|
+
# check every 6 seconds for 1 minute
|
65
|
+
login_count_checks = 0
|
66
|
+
until @logged_in || (login_count_checks >= 60) do
|
67
|
+
puts "\t Checking if logged in"
|
68
|
+
@logged_in = get_add_question_div.exists?
|
69
|
+
login_count_checks+=1
|
70
|
+
sleep 1
|
83
71
|
end
|
84
72
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
73
|
+
if @logged_in then
|
74
|
+
puts "Successfully logged in!"
|
75
|
+
elsif @browser.text_field(:name=> "email", :class=>/header_login_text_box/).exist? then
|
76
|
+
puts "There was an error logging in. Most likely a wrong username or password."
|
77
|
+
else
|
78
|
+
puts "There was an error logging in."
|
90
79
|
end
|
80
|
+
self.login
|
81
|
+
end
|
91
82
|
|
92
|
-
|
93
|
-
|
94
|
-
|
83
|
+
def goto(login = nil)
|
84
|
+
@browser.goto "#{@url}#{login.nil? ? '?share=1' : ''}"
|
85
|
+
unless login.nil? then
|
86
|
+
self.login
|
95
87
|
end
|
88
|
+
end
|
96
89
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
90
|
+
def home
|
91
|
+
@url = "#{@base_url}"
|
92
|
+
self.goto :login
|
93
|
+
end
|
101
94
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
95
|
+
def answers
|
96
|
+
@url = "#{@base_url}#{self.stringify}/answers?share=1"
|
97
|
+
self.goto
|
98
|
+
end
|
99
|
+
|
100
|
+
def content(subcategory = :all)
|
101
|
+
case subcategory
|
102
|
+
when :questions_added,
|
103
|
+
:questions_followed,
|
104
|
+
:answers,
|
105
|
+
:posts
|
106
|
+
@url = "#{@base_url}content?content_types=#{subcategory}"
|
107
|
+
else
|
108
|
+
@url = "#{@base_url}content"
|
113
109
|
end
|
110
|
+
self.goto :login
|
111
|
+
end
|
114
112
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
113
|
+
def scroll_n_times(n = 1)
|
114
|
+
n.times do
|
115
|
+
@browser.scroll.to :bottom
|
119
116
|
end
|
117
|
+
end
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
119
|
+
def get_all
|
120
|
+
last_size = 0
|
121
|
+
while last_size != self.html.size do
|
122
|
+
last_size = self.html.size
|
123
|
+
@browser.scroll.to :bottom
|
124
|
+
# sleep for 3 seconds to handle ajax request delay until page updates
|
125
|
+
sleep 3
|
129
126
|
end
|
130
127
|
end
|
131
128
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module QuoraWebDriver
|
2
|
+
class Stats
|
3
|
+
attr_reader :notifs, :openqs
|
4
|
+
|
5
|
+
def initialize(browser)
|
6
|
+
@browser = browser
|
7
|
+
end
|
8
|
+
|
9
|
+
def notifs
|
10
|
+
el = @browser.div(:class=>/NotifsNavItem/).span(:class=>/badge/)
|
11
|
+
@notifs ||= (el.text.to_i && el.exist?) || 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def openqs
|
15
|
+
el = @browser.div(:class=>/OpenQsNavItem/).span(:class=>/badge/)
|
16
|
+
@openqs ||= (el.text.to_i && el.exist?) || 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/quora-webdriver.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'quora-webdriver/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "quora-webdriver"
|
8
|
-
spec.version =
|
8
|
+
spec.version = QuoraWebDriver::VERSION
|
9
9
|
spec.authors = ["Giordon Stark"]
|
10
10
|
spec.email = ["kratsg@gmail.com"]
|
11
11
|
spec.summary = %q{Interact with Quora via Command Line}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quora-webdriver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giordon Stark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: watir-webdriver
|
@@ -108,8 +108,9 @@ files:
|
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
110
|
- lib/quora-webdriver.rb
|
111
|
-
- lib/quora-webdriver/
|
111
|
+
- lib/quora-webdriver/base.rb
|
112
112
|
- lib/quora-webdriver/quora.rb
|
113
|
+
- lib/quora-webdriver/stats.rb
|
113
114
|
- lib/quora-webdriver/version.rb
|
114
115
|
- quora-webdriver.gemspec
|
115
116
|
- spec/quora_login.html
|