app/models/tutorial.rb
# sync tutorial posts from rss feed
sync tutorial posts from rss feed
sync tutorial posts from rss feed
def sync
    require 'open-uri'
    feed = Feedjira::Feed.fetch_and_parse(self.rss_feed)
    items = feed.entries
    posts = []
    items.each do |item|
      post = Post.new :title => item.title, :link => item.url, :created_at => item.published
      posts << post
    end
    posts.each do |post|
      next if self.created_at < self.updated_at and post.created_at < self.updated_at
      acceptFlg = true
      self.filters.each do |filter|
        if not filter.accept? post
          acceptFlg = false 
        end
      end
      if acceptFlg
        post.save
        self.posts << post 
      end
    end
    self.updated_at = Time.now
    self.save
  end
def sync require 'open-uri' feed = Feedjira :: Feed . fetch_and_parse ( self . rss_feed ) items = feed . entries posts = [ ] items . each do | item | post = Post . new :title => item . title , :link => item . url , :created_at => item . published posts << post end posts . each do | post | next if self . created_at < self . updated_at and post . created_at < self . updated_at acceptFlg = true self . filters . each do | filter | if not filter . accept? post acceptFlg = false end end if acceptFlg post . save self . posts << post end end self . updated_at = Time . now self . save end
sync tutorial posts from rss feed
sync tutorial posts from rss feed
# fetch and parse rss feed # get all posts # filtering # ignore old posts # post.created_at < tutorial.updated_at: post is synced # tutorial.created_at < tutorial.updated_at: the tutorial is new to first sync # filtering # post will not accpet # append post to tutorial posts # save tutorial changes and update updated_at