Created
June 17, 2013 23:49
-
-
Save anonymous/5801535 to your computer and use it in GitHub Desktop.
fee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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