Skip to content

Instantly share code, notes, and snippets.

@johnivanoff
Last active October 13, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnivanoff/4247690 to your computer and use it in GitHub Desktop.
Save johnivanoff/4247690 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'nokogiri'
require 'open-uri'
feed = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=1373979@N22&lang=en-us&format=rss_200'
def parse feed
doc = Nokogiri::XML(open(feed))
doc.search('item').map do |doc_item|
item = {}
item[:link] = doc_item.at('link').text
item[:thumbnail] = doc_item.at('media|thumbnail').attr('url')
item[:title] = doc_item.at('title').text
item
end
end
get '/' do
@pictures = parse feed
erb :index
end
__END__
@@index
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="user-scalable=yes, width=device-width" />
<title>Lovely Sunsets</title>
</head>
<body>
<h1>Lovely Sunsets</h1>
<dl>
<% @pictures.each do |picture| %>
<dt><a href="<%= picture[:link] %>"><%= picture[:title] %></a></dt>
<dd><img src="<%= picture[:thumbnail] %>" /></dd>
<% end %>
</dl>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment