Convert Open Plaques CSV export file to GeoRSS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

63 lignes
1.4 KiB

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