Skip to content

Instantly share code, notes, and snippets.

@kookjr
Created February 27, 2010 06:50
Show Gist options
  • Save kookjr/316526 to your computer and use it in GitHub Desktop.
Save kookjr/316526 to your computer and use it in GitHub Desktop.
create test rss feed
# Create a test RSS feed based on the .mp3 files in the current directory.
# Usage: ruby rssfeed.rb > rss.xml
# ==== RSS header ===========================================================
header_markup = '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Your title goes here</title>
<description>Your RSS feed description goes here</description>
<link>http://www.rssFeedFolder.com/</link>
<language>en</language>
<copyright>rssFeedFolder.com</copyright>
<pubDate>Fri, 07 Dec 2007 21:58:26 CST</pubDate>
<lastBuildDate>Fri, 07 Dec 2007 21:58:26 CST</lastBuildDate>
<generator>rssFeedFolder.com</generator>
<ttl>30</ttl>
<atom:link href="http://www.yourdomain.com/yourfeed.xml" rel="self" type="application/rss+xml" />
<image>
<title>Your title goes here</title>
<url>http://www.rssFeedFolder.com/images/rssFeedFolderLogo.gif</url>
<link>http://www.rssFeedFolder.com/</link>
<description>your RSS feed description goes here</description>
</image>
'
# ==== RSS item =============================================================
item_markup = '
<item>
<title>Your first feed file goes here</title>
<description>A brief description of the file goes here</description>
<link>http://www.yourdomain.com/rssfeedfolder/file1.html</link>
<guid isPermaLink="true">http://www.yourdomain.com/rssfeedfolder/file1.html</guid>
<pubDate>Tue, 04 Dec 2007 09:19:42 CST</pubDate>
<source url="http://www.rssFeedFolder.com/">rssFeedFolder.com</source>
<enclosure url="http://localhost:8080/%%filename%%" length="%%length%%" type="audio/mpeg" />
</item>
'
# ==== RSS footer =============================================================
footer_markup = '
</channel>
</rss>
'
# ==== some code ============================================================
puts header_markup
Dir.glob("*.mp3").each do |item_file|
puts item_markup.gsub(/%%filename%%/, item_file).gsub(/%%length%%/, File.size(item_file).to_s)
end
puts footer_markup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment