#!/usr/bin/env ruby

require 'csv'
require 'geocoder'
require 'json'

locations = []

# "Antrim CAB","Farranshane House","1 Ballygore Road","Antrim","BT41 2RN"
CSV.foreach('nicab.csv', headers: true, return_headers: false) do |row|
  title = row.fields.first.strip
  address = row.fields[1..4].reject { |value| value.nil? || value.strip == '' }.map(&:strip).join(', ')
  lat, lng = Geocoder.coordinates(address)

  locations << {
    title: title,
    address: address,
    phone: '',
    lat: lat,
    lng: lng
  }
end

puts JSON.pretty_generate(locations)

#!/usr/bin/env ruby

require 'csv'
require 'geocoder'
require 'json'

locations = []

# "Antrim","Farranshane House","1 Ballygore Road","Antrim","BT41 2RN","028 9442 8176"
CSV.foreach('nicab.csv', headers: true, return_headers: false) do |row|
  title = row.fields.first.strip
  address = row.fields[1..4].reject { |value| value.nil? || value.strip == '' }.map(&:strip).join(', ')
  phone = row.fields.last.strip
  lat, lng = Geocoder.coordinates(address)

  locations << {
    title: "#{title} Citizens Advice Bureau",
    address: address,
    phone: phone,
    lat: lat,
    lng: lng
  }
  #sleep(1)
end

puts JSON.pretty_generate(locations)

Update NICAB script to handle most recent CSV
Update NICAB script to handle most recent CSV
