Last active
December 17, 2015 03:59
-
-
Save adrianshort/5547284 to your computer and use it in GitHub Desktop.
Convert Open Plaques CSV export file to GeoRSS
This file contains hidden or 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
require 'csv' | |
require 'pp' | |
require 'erb' | |
require 'time' | |
# https://gist.github.com/adrianshort/5547284 | |
# $ 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 => "Plaque Guide", | |
:link => "http://www.plaqueguide.com/", | |
:description => "" | |
} | |
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 => "[email protected]", | |
:guid => link, | |
:lat => row[5], | |
:long => row[6] | |
} | |
items << item | |
end | |
puts template.result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment