Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2013 23:49
Show Gist options
  • Save anonymous/5801535 to your computer and use it in GitHub Desktop.
Save anonymous/5801535 to your computer and use it in GitHub Desktop.
fee
class FeedEntry < ActiveRecord::Base
def self.update_from_feed(feed_url)
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
end
def self.update_from_feed_continuously(feed_url, delay_interval = 15.minutes)
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
loop do
sleep delay_interval
feed = Feedzirra::Feed.update(feed)
add_entries(feed.new_entries) if feed.updated?
end
end
private
def self.add_entries(entries)
entries.each do |entry|
unless exists? :guid => entry.id
create!(
:name => entry.title,
:summary => entry.summary,
:url => entry.url,
:published_at => entry.published,
:guid => entry.id
)
end
end
end
end
<div id="new_songs">
<h2 class="hype"><%= link_to "New music", 'http://newmusic.com' %></h2>
<hr />
<h3>Top 20 new songs</h3>
<ol>
<% for entry in FeedEntry.all(:limit => 20, :order => "published_at desc") %>
<li class="posts"><%= link_to h(entry.name), entry.url %></li><br />
<% end %>
</ol>
</div>
<div id="new_songs">
<h2 class="ninja"><%= link_to "Newer music", 'http://newer.com' %></h2>
<hr />
<h3>Top 20 new songs</h3>
<ol>
<% for entry in FeedEntry.all(:limit => 20, :order => "published_at desc") %>
<li class="posts"><%= link_to h(entry.name), entry.url %></li><br />
<% end %>
</ol>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment