everyx 1.0.2 → 1.0.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.
- data/History.txt +4 -0
- data/README.txt +1 -0
- data/lib/everyx.rb +56 -1
- metadata +2 -2
data/History.txt
CHANGED
data/README.txt
CHANGED
data/lib/everyx.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Everyx
|
|
2
|
-
VERSION = '1.0.
|
|
2
|
+
VERSION = '1.0.3'
|
|
3
3
|
|
|
4
4
|
# The class that responsible for running the periodic task
|
|
5
5
|
class Everyx
|
|
@@ -38,6 +38,12 @@ module Everyx
|
|
|
38
38
|
# every the file modification time changes.
|
|
39
39
|
#
|
|
40
40
|
# You'll have to set the +fname+ for the file.
|
|
41
|
+
#
|
|
42
|
+
# Example:
|
|
43
|
+
#
|
|
44
|
+
# fm = Everyx::PeriodicTasks::FileMonitor.new
|
|
45
|
+
# fm.fname = '/tmp/file.txt'
|
|
46
|
+
#
|
|
41
47
|
class FileMonitor
|
|
42
48
|
require 'rubygems'
|
|
43
49
|
require 'nserver'
|
|
@@ -74,6 +80,11 @@ module Everyx
|
|
|
74
80
|
# owner. 15 minutes is fairly "standard."
|
|
75
81
|
#
|
|
76
82
|
# You'll have to set the +uri+ before you schedule this.
|
|
83
|
+
#
|
|
84
|
+
# Example:
|
|
85
|
+
#
|
|
86
|
+
# rss = Everyx::PeriodicTasks::RSSNotifier.new
|
|
87
|
+
# rss.uri = "http://www.slashdot.org/slash.rss"
|
|
77
88
|
class RSSNotifier
|
|
78
89
|
require 'rss/1.0'
|
|
79
90
|
require 'rss/2.0'
|
|
@@ -109,6 +120,50 @@ module Everyx
|
|
|
109
120
|
|
|
110
121
|
end
|
|
111
122
|
|
|
123
|
+
# This class will monitor a normal URI and notify on changes
|
|
124
|
+
# that match a pattern.
|
|
125
|
+
#
|
|
126
|
+
# Example:
|
|
127
|
+
#
|
|
128
|
+
# htmlmon = Everyx::PeriodicTasks::HTMLMonitor.new
|
|
129
|
+
# htmlmon.uri = "http://www.slashdot.org/"
|
|
130
|
+
# htmlmon.pattern = "//div[@class='title']//a"
|
|
131
|
+
#
|
|
132
|
+
# The class uses Hpricot to parse HTML, which accepts either XPath
|
|
133
|
+
# or CSS-like selectors to match.
|
|
134
|
+
class HTMLMonitor
|
|
135
|
+
require 'hpricot'
|
|
136
|
+
require 'open-uri'
|
|
137
|
+
|
|
138
|
+
attr :uri, :writable => true
|
|
139
|
+
attr :pattern, :writable => true
|
|
140
|
+
|
|
141
|
+
def initialize
|
|
142
|
+
@uri = nil
|
|
143
|
+
@last = nil
|
|
144
|
+
@pattern = nil
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def call
|
|
148
|
+
doc = Hpricot( open(uri) {|f| f.read } )
|
|
149
|
+
new = []
|
|
150
|
+
new_last = nil
|
|
151
|
+
doc.search( @pattern ).each do |ele|
|
|
152
|
+
if ele.inner_html != @last
|
|
153
|
+
new << ele.inner_html
|
|
154
|
+
new_last = new.last unless new_last
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
@last = new_last if new_last
|
|
158
|
+
if new.size > 0
|
|
159
|
+
msg = NServer::Message.new
|
|
160
|
+
msg.title = "Website updated."
|
|
161
|
+
msg.text = new.collect {|n| "* #{n}"}.join("\n")
|
|
162
|
+
NServer::Client.try_notify( msg )
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
112
167
|
end
|
|
113
168
|
end
|
|
114
169
|
|
metadata
CHANGED
|
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.5
|
|
|
3
3
|
specification_version: 2
|
|
4
4
|
name: everyx
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 1.0.
|
|
7
|
-
date: 2007-11-
|
|
6
|
+
version: 1.0.3
|
|
7
|
+
date: 2007-11-14 00:00:00 -05:00
|
|
8
8
|
summary: Code to run some classes every x seconds
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|