Election results in the London Borough of Sutton.
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.

import.rb 1.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. require 'rubygems'
  2. require 'csv'
  3. require 'dm-core'
  4. require 'dm-validations'
  5. require 'dm-timestamps'
  6. require 'lib/models'
  7. # Define parties
  8. # parties = [
  9. # "British National Party",
  10. # "Christian Peoples Alliance",
  11. # "Conservative Party",
  12. # "Green Party",
  13. # "Labour Party",
  14. # "Labour and Co-Operative Party",
  15. # "Liberal Democrats",
  16. # "United Kingdom Independence Party",
  17. # "Libertarian Party"
  18. # ]
  19. #
  20. # for party in parties
  21. # puts party
  22. # Party.create( :name => party )
  23. # end
  24. # Import council candidates
  25. # CSV::Reader.parse(File.open('../candidates-pretty.csv', 'rb')) do |row|
  26. # p row
  27. #
  28. # c = Councilcandidate.new(
  29. # 'forenames' => row[1],
  30. # 'surname' => row[2],
  31. # 'address' => row[4],
  32. # 'postcode' => row[5]
  33. # )
  34. #
  35. # c.ward = Ward.first( :name => row[0] )
  36. # c.party = Party.first( :name => row[3] )
  37. #
  38. # unless c.save
  39. # puts "ERROR: Failed to save candidate"
  40. # c.errors.each do |e|
  41. # puts e
  42. # end
  43. # end
  44. # end
  45. # Import parliament candidates
  46. CSV::Reader.parse(File.open('../parliament-candidates.csv', 'rb')) do |row|
  47. p row
  48. c = Parliamentcandidate.new(
  49. 'forenames' => row[1],
  50. 'surname' => row[2]
  51. )
  52. c.constituency = Constituency.first( :name => row[3] )
  53. c.party = Party.first( :name => row[0] )
  54. unless c.save
  55. puts "ERROR: Failed to save candidate"
  56. c.errors.each do |e|
  57. puts e
  58. end
  59. end
  60. end