Created
October 11, 2013 17:55
-
-
Save adamcrown/6939180 to your computer and use it in GitHub Desktop.
Converts an Everbridge.net group export CSV file into a SQL query to insert data into the everbridge_user table in Biola's WS database. The purpose being to resync WS with Everbridge if it has gotten out of sync.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'csv' | |
file = ARGV.first | |
TABLE = 'everbridge_user' | |
date_modified = Time.now.strftime '%Y-%m-%d %H:%M:%S' | |
CSV.foreach(file, headers: :first_row) do |row| | |
fields = { | |
date_modified: date_modified, | |
idnumber: row['External Id'], | |
firstname: row['First Name'], | |
lastname: row['Last Name'].to_s.gsub("'", "''"), | |
email: row['E-mail Address'], | |
cell: row['Mobile Phone'].to_s.gsub(/[^0-9]/, ''), | |
groups: row['Member Of Group'] | |
} | |
fields.each { |key, val| fields[key] = val.to_s.strip } | |
if fields[:idnumber] != '' | |
puts "INSERT INTO #{TABLE} (#{fields.keys.join(', ')}) VALUES('#{fields.values.join("', '")}');" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment