| @@ -0,0 +1,13 @@ | |||||
| require 'csv' | |||||
| require './models' | |||||
| CSV.foreach(ARGV.shift) do |row| | |||||
| pc = row[0].strip | |||||
| puts pc | |||||
| if @postcode = Postcode.get(pc) | |||||
| @postcode.polling_station_id = row[1] | |||||
| @postcode.save | |||||
| else | |||||
| puts "#{pc} not found" | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,25 @@ | |||||
| # load polling districts data | |||||
| require './models' | |||||
| require 'csv' | |||||
| require 'pp' | |||||
| DataMapper::Model.raise_on_save_failure = true | |||||
| PollingStation.destroy | |||||
| CSV.foreach(ARGV.shift, :headers => true) do |row| | |||||
| begin | |||||
| @p = PollingStation.create( | |||||
| :id => row['District'].strip, | |||||
| :easting => row['Eastings'], | |||||
| :northing => row['Northings'], | |||||
| :lat => row['lat'], | |||||
| :lng => row['lng'] | |||||
| ) | |||||
| @p.save | |||||
| rescue | |||||
| pp @p | |||||
| # puts p.errors | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,24 @@ | |||||
| # load polling stations data (polling-stations.csv) | |||||
| require './models' | |||||
| require 'csv' | |||||
| require 'pp' | |||||
| DataMapper::Model.raise_on_save_failure = true | |||||
| CSV.foreach(ARGV.shift, :headers => false) do |row| | |||||
| begin | |||||
| if @p = PollingStation.get(row[1]) | |||||
| @p.name = row[2] | |||||
| @p.address = row[3] | |||||
| @p.postcode = row[4] | |||||
| @p.save | |||||
| else | |||||
| puts "#{row[1]} not found" | |||||
| end | |||||
| rescue | |||||
| puts @p.saved? | |||||
| pp @p | |||||
| @p.errors.each { |r| puts r } | |||||
| end | |||||
| end | |||||