Reputation: 167
I use ruby on rails, mongoid and feedjira to parse RSS links.
How to add a limit for the number of saved feed_entries
at a time or a limit by the date of the link?
For example save only last 10 feed_enties.
My code:
def load_feed_entries
feed = Feedjira::Feed.fetch_and_parse(self.url)
Source.add_entries(feed.entries, self.id)
end
private
def self.add_entries(entries, stream_id)
entries.each do |entry|
unless FeedEntry.where(guid: entry.id).exists?
FeedEntry.create!(
:link => entry.url,
:published_at => entry.published,
:guid => entry.id,
)
end
end
end
Upvotes: 0
Views: 50