-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppController.rb
108 lines (93 loc) · 2.86 KB
/
AppController.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# AppController.rb
# WhereDoIRankRuby
#
# Created by Jason Amster on 3/14/09.
# Copyright (c) 2009 __MyCompanyName__. All rights reserved.
#
require 'osx/cocoa'
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'googlepagerank'
class AppController < OSX::NSObject
attr_accessor :iteration, :counter, :pr
attr_accessor :domainField,
:xpathField,
:searchField,
:progress,
:counterLabel,
:urlLabel,
:progressBar,
:stopButton,
:prLabel
ib_outlet :domainField,
:xpathField,
:searchField,
:progress,
:counterLabel,
:urlLabel,
:progressBar,
:stopButton,
:prLabel
def awakeFromNib
@counter = 0
@iteration = 0
domainField.setStringValue "http://www.beenverified.com"
xpathField.setStringValue "//body/div[@id='res']/div[1]/ol/li/h3/a"
searchField.setStringValue "Background Checks"
counterLabel.setStringValue ""
progressBar.setUsesThreadedAnimation true
end
def stopIt(sender)
@iteration = 21
end
ib_action :stopIt
def displayIt(sender)
Thread.start do
sender.setEnabled(false)
stopButton.setEnabled(true)
progressBar.startAnimation(sender)
doIt(sender)
progressBar.stopAnimation(sender)
progressBar.setDoubleValue(0.0)
sender.setEnabled(true)
stopButton.setEnabled(false)
end
end
def doIt(sender)
counterLabel.setStringValue ""
counter = 0
xpath = xpathField.stringValue
puts self.searchField.stringValue
not_found = true
@iteration = 0
while not_found && @iteration < 20 do
progressBar.incrementBy 5.0
#puts "PRogres #{progressBar.value}"
searchTerm = searchField.stringValue.gsub(/\s+/, '+')
url = "http://www.google.com/search?hl=en&rls=ig&q=#{searchTerm}&start=#{@iteration*10}&sa=N"
xml = open(url).read
doc = Hpricot xml
links = doc/xpath
links.each_with_index do |link, index|
puts link["href"]
if link['href'] =~ /#{domainField.stringValue}/
counter = index + 1 + (10 * @iteration)
counterLabel.setStringValue "Your Position is: #{counter}"
urlLabel.setStringValue "URL: #{link['href']}"
progressBar.setDoubleValue(100.0)
not_found = false
end
end
@iteration = @iteration + 1
end
@pr = GooglePageRank.get(domainField.stringValue)
prLabel.setStringValue "The page rank for that URL is: #{@pr}"
if counter == 0
counterLabel.setStringValue "Jeez, you don't have any ranking (Better get going on SEO)"
end
puts "Finishiging Up"
end
ib_action :displayIt
end