Election results in the London Borough of Sutton.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

load-polling-stations.rb 469 B

123456789101112131415161718192021222324
  1. # load polling stations data (polling-stations.csv)
  2. require './models'
  3. require 'csv'
  4. require 'pp'
  5. DataMapper::Model.raise_on_save_failure = true
  6. CSV.foreach(ARGV.shift, :headers => false) do |row|
  7. begin
  8. if @p = PollingStation.get(row[1])
  9. @p.name = row[2]
  10. @p.address = row[3]
  11. @p.postcode = row[4]
  12. @p.save
  13. else
  14. puts "#{row[1]} not found"
  15. end
  16. rescue
  17. puts @p.saved?
  18. pp @p
  19. @p.errors.each { |r| puts r }
  20. end
  21. end