-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ticker.rb
66 lines (53 loc) · 1.23 KB
/
Ticker.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
require 'nokogiri'
require 'rubygems'
require 'rest_client'
require 'ruby_gntp'
require_relative 'C:\Ruby\ForumThreadChecker\Notify.rb'
class Ticker
def initialize(minutes, base_url)
@minutes = minutes
@base_url = base_url
@url = base_url
@note = Notify.new()
end
def start_ticker()
ticker()
end
def ticker()
posts_then = 0
loop do
check_site() {|posts_now, new_page|
if new_page != 0
@note.send_message("New Page and new posts in Thread")
posts_then = 1
elsif posts_now != posts_then
@note.send_message("New posts in Thread")
posts_then = posts_now
end
}
sleep(@minutes*60)
end
end
def check_site()
count = 0
last_page = 0
doc = Nokogiri::HTML(RestClient.get(@url))
link = doc.css('span/a[@class = "popupctrl"]')
page = link.text.scan /[-+]?\d*\.?\d+/
if page != []
if ((@base_url + "&page=" + page[1]) != @url)
@url = @base_url + "&page=" + page[1]
last_page = 1
end
end
doc.css('a.postcounter').each do |node|
count = count + 1
end
yield(count, last_page)
end
end
def test
ticker = Ticker.new(1, "http://forum.bodybuilding.com/showthread.php?t=139437963&page=1")
ticker.start_ticker
end
test