Convert Open Plaques CSV export file to GeoRSS
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

62 linhas
1.5 KiB

  1. require 'csv'
  2. require 'pp'
  3. require 'erb'
  4. require 'time'
  5. # $ ruby csv2georss.rb myfile.csv > feed.xml
  6. template = ERB.new <<-EOF
  7. <?xml version="1.0" encoding="UTF-8" ?>
  8. <rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  9. <channel>
  10. <title><%= channel[:title] %></title>
  11. <link><%= channel[:link] %></link>
  12. <description><%= channel[:description] %></description>
  13. <pubDate><%= Time.now.rfc822 %></pubDate>
  14. <% items.each do |item| %>
  15. <item>
  16. <title><%= item[:title] %></title>
  17. <link><%= item[:link] %></link>
  18. <description><![CDATA[<%= item[:description] %>]]></description>
  19. <pubDate><%= item[:pubDate] %></pubDate>
  20. <author><%= item[:author] %></author>
  21. <guid isPermalink="true"><%= item[:guid] %></guid>
  22. <geo:lat><%= item[:lat] %></geo:lat>
  23. <geo:long><%= item[:long] %></geo:long>
  24. </item>
  25. <% end %>
  26. </channel>
  27. </rss>
  28. EOF
  29. channel = {
  30. :title => "Open Plaques",
  31. :link => "http://openplaques.org/",
  32. :description => "Documenting the historical links between people and places, as recorded by commemorative plaques."
  33. }
  34. items = []
  35. line = 0
  36. CSV.foreach(ARGV[0]) do |row|
  37. line += 1
  38. next if line == 1 # skip header row
  39. link = "http://www.plaqueguide.com/?locationid=" + row[0]
  40. item = {
  41. :id => row[0], # id
  42. :title => row[3], # location
  43. :link => link,
  44. :description => row[32], # note1
  45. :pubDate => Time.now.rfc822,
  46. :author => "feedback@openplaques.org",
  47. :guid => link,
  48. :lat => row[5],
  49. :long => row[6]
  50. }
  51. items << item
  52. end
  53. puts template.result