Просмотр исходного кода

Add script to import May 2014 local election results

tags/last-sinatra-version
Adrian Short 9 лет назад
Родитель
Сommit
b69d3e9fe8
1 измененных файлов: 40 добавлений и 0 удалений
  1. +40
    -0
      scripts/import-2014-local.rb

+ 40
- 0
scripts/import-2014-local.rb Просмотреть файл

@@ -0,0 +1,40 @@
# load 2014 council results

require './models'
require 'csv'
require 'pp'

DataMapper::Model.raise_on_save_failure = true

@found = 0

CSV.foreach(ARGV.shift, :headers => true) do |row|
begin
if @candidate = Candidate.first(:forenames => row['Forenames'], :surname => row['Surname'])
@found += 1
@ccy = @candidate.candidacies.last
if @ccy.election_id == 8
@ccy.votes = row['Votes']
@ccy.save
end
# pp @ccy
end
# pp @candidate

# @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

puts @found

Загрузка…
Отмена
Сохранить