Election results in the London Borough of Sutton.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

61 rinda
1.2 KiB

  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