everyx 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/History.txt +4 -0
  2. data/README.txt +1 -0
  3. data/lib/everyx.rb +56 -1
  4. metadata +2 -2
@@ -1,3 +1,7 @@
1
+ == 1.0.3 / 2007-11-14
2
+
3
+ * New HTMLMonitor task
4
+
1
5
  == 1.0.2 / 2007-11-13
2
6
 
3
7
  * Remove some debugging output
data/README.txt CHANGED
@@ -29,6 +29,7 @@ The requirements listed below are not for Everyx, but for the periodic tasks. E
29
29
  * rss
30
30
  * open-uri
31
31
  * nserver
32
+ * hpricot
32
33
 
33
34
  == INSTALL:
34
35
 
@@ -1,5 +1,5 @@
1
1
  module Everyx
2
- VERSION = '1.0.2'
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.2
7
- date: 2007-11-13 00:00:00 -05:00
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