|
- require 'csv'
- require 'pp'
- require 'erb'
- require 'time'
-
- # $ ruby csv2georss.rb myfile.csv > feed.xml
-
- template = ERB.new <<-EOF
- <?xml version="1.0" encoding="UTF-8" ?>
- <rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
- <channel>
- <title><%= channel[:title] %></title>
- <link><%= channel[:link] %></link>
- <description><%= channel[:description] %></description>
- <pubDate><%= Time.now.rfc822 %></pubDate>
- <% items.each do |item| %>
- <item>
- <title><%= item[:title] %></title>
- <link><%= item[:link] %></link>
- <description><![CDATA[<%= item[:description] %>]]></description>
- <pubDate><%= item[:pubDate] %></pubDate>
- <author><%= item[:author] %></author>
- <guid isPermalink="true"><%= item[:guid] %></guid>
- <geo:lat><%= item[:lat] %></geo:lat>
- <geo:long><%= item[:long] %></geo:long>
- </item>
- <% end %>
- </channel>
- </rss>
- EOF
-
- channel = {
- :title => "Open Plaques",
- :link => "http://openplaques.org/",
- :description => "Documenting the historical links between people and places, as recorded by commemorative plaques."
- }
-
- items = []
- line = 0
-
- CSV.foreach(ARGV[0]) do |row|
- line += 1
- next if line == 1 # skip header row
-
- link = "http://www.plaqueguide.com/?locationid=" + row[0]
-
- item = {
- :id => row[0], # id
- :title => row[3], # location
- :link => link,
- :description => row[32], # note1
- :pubDate => Time.now.rfc822,
- :author => "feedback@openplaques.org",
- :guid => link,
- :lat => row[5],
- :long => row[6]
- }
- items << item
- end
-
- puts template.result
|