The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Creating the new feed files

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Green

Posts: 102
Nickname: darwinian
Registered: Dec, 2005

Adam Green is the author of Ruby.Darwinianweb.com
Creating the new feed files Posted: Jan 7, 2006 4:10 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Adam Green.
Original Post: Creating the new feed files
Feed Title: ruby.darwinianweb.com
Feed URL: http://www.nemesis-one.com/rss.xml
Feed Description: Adam Green's Ruby development site
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Adam Green
Latest Posts From ruby.darwinianweb.com

Advertisement
Here is the code for generating the new merged feeds.

make_xml.rb

 #! /usr/bin/ruby



# Save the array of feed items as an XML file.
# If the requested type is RSS, a standard RSS feed will be created.
# Otherwise the file requested will include the full feed title and link for use
# in generating the web page.



def make_xml(itemlist, type)



file = File.new( type + '.xml','w')
file.puts('<?xml version="1.0"?>')



if type == 'rss'
file.puts('<rss version="2.0">')
else
file.puts('<' + type + '>')
end



# Write out the XML header.
file.puts(' <channel>')
file.puts(' <title>' + get_param('rubyriver.yml','sitetitle') + '</title>')
file.puts(' <link>' + get_param('rubyriver.yml','sitelink') + '</link>')
file.puts(' <description>' + get_param('rubyriver.yml','sitedescription') + '</description>')
file.puts(' <language>' + get_param('rubyriver.yml','sitelanguage') + '</language>')
file.puts(' <copyright>' + get_param('rubyriver.yml','sitecopyright') + '</copyright>')
file.puts(' <pubDate>' + Time.now.rfc2822 + '</pubDate>')
file.puts(' <lastBuildDate>' + Time.now.rfc2822 + '</lastBuildDate>')
file.puts(' <generator>RubyRiver 0.1</generator>')



# Write out each feed item.
itemlist.each do |item|



# Each element of the itemlist array has the following structure:
# [pubdate, {pubdate,title,description,link,feedlink,feedtitle}]
# The hash containing the item's data will be used to generate a new RSS item.
current_item = item[1]
file.puts(' <item>')
if type != 'rss'
file.puts(' <feedtitle>' + current_item['feedtitle'] + '</feedtitle>')
file.puts(' <feedlink>' + current_item['feedlink'] + '</feedlink>')
end
file.puts(' <pubDate>' + current_item['pubdate'] + '</pubDate>')
file.puts(' <title>' + current_item['title'] + '</title>')
file.puts(' <link>' + current_item['link'] + '</link>')
file.puts(' <description>' + current_item['description'] + '</description>')
file.puts(' <guid>' + current_item['link'] + '</guid>')
file.puts(' </item>')
end



file.puts(' </channel>')
file.puts('</' + type + '>')
file.close
end

Read: Creating the new feed files

Topic: Excerpting HTML Previous Topic   Next Topic Topic: Mad Propz to Wikipedia

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use