Election results in the London Borough of Sutton.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require 'rubygems'
  2. require 'csv'
  3. require 'dm-core'
  4. require 'dm-validations'
  5. require 'dm-timestamps'
  6. require 'lib/models'
  7. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  8. DataMapper.auto_upgrade!
  9. # Import wards
  10. CSV::Reader.parse(File.open('wards.csv', 'rb')) do |row|
  11. p row
  12. Ward.create(
  13. 'ons_id' => row[0],
  14. 'name' => row[1]
  15. )
  16. end
  17. # Define parties
  18. parties = [
  19. "British National Party",
  20. "Christian Peoples Alliance",
  21. "Conservative Party",
  22. "Green Party",
  23. "Labour Party",
  24. "Labour and Co-Operative Party",
  25. "Liberal Democrats",
  26. "United Kingdom Independence Party"
  27. ]
  28. for party in parties
  29. puts party
  30. Party.create( :name => party )
  31. end
  32. # Import candidates
  33. CSV::Reader.parse(File.open('../candidates-pretty.csv', 'rb')) do |row|
  34. p row
  35. c = Councilcandidate.new(
  36. 'forenames' => row[1],
  37. 'surname' => row[2],
  38. 'address' => row[4],
  39. 'postcode' => row[5]
  40. )
  41. c.ward = Ward.first( :name => row[0] )
  42. c.party = Party.first( :name => row[3] )
  43. unless c.save
  44. puts "ERROR: Failed to save candidate"
  45. c.errors.each do |e|
  46. puts e
  47. end
  48. end
  49. end