public
Description: A fork of CyBot (http://repo.or.cz/w/six.git)
Homepage: http://wiki.macromates.com/Cybot/Cybot
Clone URL: git://github.com/kballard/six.git
Add new items to the permanent database of seen items *before* truncating 
the array.

Previously it would truncate the new items array to 6 items before adding 
them to the permanent database. This meant that next time the feed was 
checked (and reported something other than “304 Not Modified”), it woul
d view those items which was cut last, as new items.

Sort the unread items before we truncate, so we always return the newest 5 
items. Also ensures that the oldest (of at most the newest 5) is first in 
the ‘unread’ array.

Since we truncate feeds to at most report 5 items, I removed the code that 
has it skip all new items when the bot is first started.

Also added to_s for the Feed class so we can see what feed URL is causing 
an exception instead of the object address.
Allan Odgaard (author)
Thu Jun 12 01:23:53 -0700 2008
commit  53b3b41eac5b6a39e088f4e94698745853108ff6
tree    83935ca9242628d843163365b00cce0f1a29c15a
parent  d0fa0e13b72a9849162035e3fa0c4c3862cbd2b8
...
26
27
28
 
29
30
31
...
115
116
117
 
 
 
 
 
 
 
 
 
 
118
119
120
...
130
131
132
133
134
135
136
...
138
139
140
 
 
141
142
143
...
150
151
152
 
 
 
 
153
154
155
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
26
27
28
29
30
31
32
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
141
142
143
 
144
145
146
...
148
149
150
151
152
153
154
155
...
162
163
164
165
166
167
168
169
170
171
...
205
206
207
 
 
 
 
 
 
 
 
 
 
 
208
209
210
0
@@ -26,6 +26,7 @@ end
0
 
0
 module FeedStuff
0
   class Resource
0
+ attr_reader :uri_string
0
     def initialize(uri_string, etag = nil)
0
       @uri_string = uri_string
0
       @etag = etag
0
@@ -115,6 +116,16 @@ module FeedStuff
0
 
0
         prefix + body + suffix
0
       end
0
+
0
+ attr_reader :item
0
+ def <=>(other)
0
+ # as of Ruby 1.8.6 the RSS library only reads pubDate, not dc::date
0
+ if @item.date and other.item.date
0
+ @item.date <=> other.item.date
0
+ else
0
+ @item.date ? 1 : (other.item.date ? -1 : 0)
0
+ end
0
+ end
0
     end
0
 
0
     def initialize(uri_string, etag = nil, last_check = nil, seen = [])
0
@@ -130,7 +141,6 @@ module FeedStuff
0
           new_items = rss.items.map { |e| Item.new(rss.channel, e, self) }
0
           new_items.reject! { |item| @seen.include? item.guid }
0
           $log.puts "Got " + new_items.size.to_s + " new items"
0
- new_items = new_items[0..5] if new_items.size > 5
0
           @seen.concat(new_items.map { |item| item.guid })
0
           @unread.concat(new_items)
0
         else
0
@@ -138,6 +148,8 @@ module FeedStuff
0
         end
0
       end
0
       @last_check = Time.now
0
+ @unread.sort!
0
+ @unread = @unread[-5..-1] if @unread.size > 5
0
       @unread.dup
0
     end
0
 
0
@@ -150,6 +162,10 @@ module FeedStuff
0
       res['last_check'] = @last_check unless @last_check.nil?
0
       res.merge(@ressource.save)
0
     end
0
+
0
+ def to_s
0
+ @ressource.uri_string
0
+ end
0
   end
0
 
0
   feeds = []
0
@@ -189,17 +205,6 @@ module FeedStuff
0
     tr = Thread.new do
0
       begin
0
         load(filename)
0
- @feeds.each do |feed|
0
- begin
0
- feed.unread.each do |item|
0
- $log.puts "Skip new item: #{item.title}"
0
- item.read = true
0
- end
0
- rescue Exception => e
0
- $log.puts "*** exception while iterating feeds (#{feed})"
0
- $log.puts Exception.pretty(e)
0
- end
0
- end
0
 
0
         while true
0
           $log.puts Time.now.strftime('%H:%M:%S: Checking feeds…')

Comments

    No one has commented yet.