Skip to content

Instantly share code, notes, and snippets.

@drewda
Created February 24, 2017 17:35
Show Gist options
  • Save drewda/c0272a5e5a3f02569ff8604218f8c0b8 to your computer and use it in GitHub Desktop.
Save drewda/c0272a5e5a3f02569ff8604218f8c0b8 to your computer and use it in GitHub Desktop.
###
# Takes in a CSV file with headers:
# - operator_onestop_id
# - country_iso
# - state_iso
# and creates a changeset to set new country and state values.
# If country_iso or state_iso is "null", it sets value to an empty string.
###
require 'csv'
require 'json'
file_name = ARGV[0]
change_payloads = []
CSV.foreach(file_name, headers: true) do |row|
country_code = (row['country_iso'] == 'null' ? "" : row['country_iso'])
state_code = (row['state_iso'] == 'null' ? "" : row['state_iso'])
change_payload = {
action: "createUpdate",
operator: {
onestopId: row['operator_onestop_id'],
country: country_code,
state: state_code
}
}
change_payloads << change_payload
end
changeset_json = {
changes: change_payloads
}
puts JSON.pretty_generate(changeset_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment