app/models/feed.rb
def process_rss(rss)
    time_offset = 1

    # taking out site/blog link and title.
    site_link = (rss/:channel/:link).first.inner_html
    site_title = (rss/:channel/:title).first.inner_html
    puts "processing rss for #{site_link}"

    (rss/:channel/:item).each do |item|
      link_raw = item.%('feedburner:origLink') || item.%('link') || (item/:link)
      link = link_raw.inner_html

      if (Item.find_by_link(link)).blank?
        rss_item = Item.new
        rss_item.feed = self
        rss_item.site_link = site_link
        rss_item.site_title = site_title
        rss_item.title = (item/:title).inner_html
        rss_item.link = link
        rss_item.author = (item/:author).inner_html
        rss_item.content = (item/:description).inner_html
        if rss.namespaces.include?("xmlns:content")
          if item.xpath('content:encoded').length == 1
            rss_item.content = item.xpath('content:encoded').inner_html
          else
            rss_item.content = (item/:description).inner_html
          end
        end

        rss_item.published = (item/:pubDate).inner_html

        if rss_item.published.blank?
          puts "rss feed published time blank. calculating system one."
          # taking it 20 days back..
          rss_item.published = (Time.now - (20*60*60*24) - time_offset.hours).to_s(:db)
          time_offset += 1
        end

        rss_item.title = htmlize(rss_item.title)
        rss_item.content = htmlize(rss_item.content, link)
        rss_item.save!
      end
    end
  end
# Process rss feed and saves it into db
Process rss feed and saves it into db
Process rss feed and saves it into db
def process_rss(rss)
    time_offset = 1
    site_link = (rss/:channel/:link).first.inner_html
    site_title = (rss/:channel/:title).first.inner_html
    puts "processing rss for #{site_link}"
    (rss/:channel/:item).each do |item|
      link_raw = item.%('feedburner:origLink') || item.%('link') || (item/:link)
      link = link_raw.inner_html
      if (Item.find_by_link(link)).blank?
        rss_item = Item.new
        rss_item.feed = self
        rss_item.site_link = site_link
        rss_item.site_title = site_title
        rss_item.title = (item/:title).inner_html
        rss_item.link = link
        rss_item.author = (item/:author).inner_html
        rss_item.content = (item/:description).inner_html
        if rss.namespaces.include?("xmlns:content")
          if item.xpath('content:encoded').length == 1
            rss_item.content = item.xpath('content:encoded').inner_html
          else
            rss_item.content = (item/:description).inner_html
          end
        end
        rss_item.published = (item/:pubDate).inner_html
        if rss_item.published.blank?
          puts "rss feed published time blank. calculating system one."
          rss_item.published = (Time.now - (20*60*60*24) - time_offset.hours).to_s(:db)
          time_offset += 1
        end
        rss_item.title = htmlize(rss_item.title)
        rss_item.content = htmlize(rss_item.content, link)
        rss_item.save!
      end
    end
  end
def process_rss ( rss ) time_offset = 1 site_link = ( rss / :channel / :link ) . first . inner_html site_title = ( rss / :channel / :title ) . first . inner_html puts "processing rss for #{site_link}" ( rss / :channel / :item ) . each do | item | link_raw = item . % ( 'feedburner:origLink' ) || item . % ( 'link' ) || ( item / :link ) link = link_raw . inner_html if ( Item . find_by_link ( link ) ) . blank? rss_item = Item . new rss_item . feed = self rss_item . site_link = site_link rss_item . site_title = site_title rss_item . title = ( item / :title ) . inner_html rss_item . link = link rss_item . author = ( item / :author ) . inner_html rss_item . content = ( item / :description ) . inner_html if rss . namespaces . include? ( "xmlns:content" ) if item . xpath ( 'content:encoded' ) . length == 1 rss_item . content = item . xpath ( 'content:encoded' ) . inner_html else rss_item . content = ( item / :description ) . inner_html end end rss_item . published = ( item / :pubDate ) . inner_html if rss_item . published . blank? puts "rss feed published time blank. calculating system one." rss_item . published = ( Time . now - ( 20 * 60 * 60 * 24 ) - time_offset . hours ) . to_s ( :db ) time_offset += 1 end rss_item . title = htmlize ( rss_item . title ) rss_item . content = htmlize ( rss_item . content , link ) rss_item . save! end end end
Process rss feed and saves it into db
Process rss feed and saves it into db
# taking out site/blog link and title. # taking it 20 days back..
rss