lib/opml_janitor.rb
##
# validate_callback tries to download a feed and verify that it has been updated
# since the +since+ time
validate_callback tries to download a feed and verify that it has been updated
since the +since+ time
validate_callback tries to download a feed and verify that it has been updated since the + since + time
def validate_callback(feed, since=nil)
      val = "FAIL"
      begin
        Timeout::timeout(@timeout) {
          open(feed[:xml_url]) do |rss|
            feed = RSS::Parser.parse(rss)
            if feed
              last_updated = Time.at(0)
              feed.items.each do |item|
                updated = nil
                if item.respond_to?(:updated)
                  updated = item.updated.content
                elsif item.respond_to?(:date)
                  updated = item.date
                end
                next unless updated
                if updated and updated > last_updated
                  last_updated = updated
                end
              end
              if since
                if last_updated and last_updated > since
                  val = "PASS"
                else
                  val = "STALE"
                end
              else
                val = "PASS"
              end
            else
              val = "NOFEED"
            end
          end
        }
      rescue EOFError => e
        val = "EOFError"
      rescue OpenURI::HTTPError => e
        val = "HTTPError"
      rescue RSS::Error => e
        val = "RSSError"
      rescue Timeout::Error => e
        val = "Timedout"
      rescue SocketError => e
        val = "SocketError"
      rescue RuntimeError => e
        val = "Redirect Loop"
      rescue Errno::ECONNREFUSED => e
        val = "Connection Refused"
      rescue Exception => e
        val = "Unexpected error: #{e}"
      end
      val      
    end
def validate_callback ( feed , since = nil ) val = "FAIL" begin Timeout :: timeout ( @timeout ) { open ( feed [ :xml_url ] ) do | rss | feed = RSS :: Parser . parse ( rss ) if feed last_updated = Time . at ( 0 ) feed . items . each do | item | updated = nil if item . respond_to? ( :updated ) updated = item . updated . content elsif item . respond_to? ( :date ) updated = item . date end next unless updated if updated and updated > last_updated last_updated = updated end end if since if last_updated and last_updated > since val = "PASS" else val = "STALE" end else val = "PASS" end else val = "NOFEED" end end } rescue EOFError => e val = "EOFError" rescue OpenURI :: HTTPError => e val = "HTTPError" rescue RSS :: Error => e val = "RSSError" rescue Timeout :: Error => e val = "Timedout" rescue SocketError => e val = "SocketError" rescue RuntimeError => e val = "Redirect Loop" rescue Errno :: ECONNREFUSED => e val = "Connection Refused" rescue Exception => e val = "Unexpected error: #{e}" end val end
validate_callback tries to download a feed and verify that it has been updated
since the +since+ time
validate_callback tries to download a feed and verify that it has been updated since the + since + time
#p item.class #p last_updated
feed
since