| @@ -11,6 +11,7 @@ gem 'rack-flash3' | |||||
| group :development do | group :development do | ||||
| gem 'shotgun' | gem 'shotgun' | ||||
| gem 'nokogiri' | |||||
| end | end | ||||
| group :production do | group :production do | ||||
| @@ -61,8 +61,11 @@ GEM | |||||
| json (1.8.6) | json (1.8.6) | ||||
| json_pure (1.8.6) | json_pure (1.8.6) | ||||
| kgio (2.11.2) | kgio (2.11.2) | ||||
| mini_portile2 (2.3.0) | |||||
| multi_json (1.13.1) | multi_json (1.13.1) | ||||
| mustermann (1.0.2) | mustermann (1.0.2) | ||||
| nokogiri (1.8.2) | |||||
| mini_portile2 (~> 2.3.0) | |||||
| pg (1.0.0) | pg (1.0.0) | ||||
| public_suffix (3.0.2) | public_suffix (3.0.2) | ||||
| rack (2.0.4) | rack (2.0.4) | ||||
| @@ -93,6 +96,7 @@ DEPENDENCIES | |||||
| data_mapper | data_mapper | ||||
| dm-postgres-adapter | dm-postgres-adapter | ||||
| haml | haml | ||||
| nokogiri | |||||
| pg | pg | ||||
| rack-flash3 | rack-flash3 | ||||
| shotgun | shotgun | ||||
| @@ -0,0 +1,23 @@ | |||||
| # Convert ModernGov XML file to CSV | |||||
| # eg https://moderngov.sutton.gov.uk/mgWebService.asmx/GetElectionResults?lElectionId=15 | |||||
| # The full API docs are at: https://moderngov.sutton.gov.uk/mgWebService.asmx | |||||
| require 'nokogiri' | |||||
| require 'csv' | |||||
| require 'pp' | |||||
| doc = File.open(ARGV.shift) { |f| Nokogiri::XML(f) } | |||||
| csv_string = CSV.generate do |csv| | |||||
| doc.search('candidates candidate').each do |cand| | |||||
| row = [] | |||||
| row << cand.at('areatitle').inner_text | |||||
| row << cand.at('candidatename').inner_text | |||||
| row << cand.at('politicalpartytitle').inner_text | |||||
| row << cand.at('numvotes').inner_text.to_i | |||||
| row << cand.at('iselected').inner_text | |||||
| csv << row | |||||
| end | |||||
| end | |||||
| puts csv_string | |||||