Last active
August 29, 2015 14:14
-
-
Save mrded/17317466b3ebf71eb07a to your computer and use it in GitHub Desktop.
Ruby: QuickTapSurvey to MailChimp converter.
This file contains hidden or 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 | |
# https://gist.github.com/mrded/17317466b3ebf71eb07a | |
require 'csv' | |
class MailChimpConverter | |
attr_accessor :columns | |
COLUMNS_HEADER = { | |
:email => 'Email Address', | |
:industry => 'Career interests', | |
:graduation_year => 'Graduation year', | |
:source => 'Source', | |
} | |
def initialize(options = {}) | |
@files = options[:files] | |
@columns = [] | |
options[:files].each { |file| fill(file) } | |
end | |
def save | |
CSV.open("output.csv", "wb") do |csv| | |
# Add header | |
csv << COLUMNS_HEADER.values | |
@columns.each { |column| csv << column.values } | |
end | |
end | |
private | |
def fill(file) | |
CSV.read(file).each do |column| | |
email = column[6] | |
@columns.push( | |
:email => email, | |
:industry => fix_industry(column[4]), | |
:graduation_year => column[5], | |
:source => File.basename(file, ".csv"), | |
) if email_is_valid?(email) | |
end | |
end | |
def email_is_valid?(email) | |
!/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/.match(email).nil? | |
end | |
def fix_industry(value) | |
# Escaping commas. | |
industries = [] | |
CSV.parse_line(value).each do |industry| | |
industries += [industry.gsub(/\,/, '\,')] # Replace ',' to '\,' | |
end | |
return industries.join(', ') | |
end | |
end | |
MailChimpConverter.new(files: ARGV).save |
Дмитрий, QuickTapSurvey поддерживает прямую интеграцию с MailChimp так что вы можете нажать ваши данные непосредственно в MailChimp. Вот ссылка, которая описывает интеграцию: http://support.quicktapsurvey.com/support/solutions/articles/199594-exporting-responses-email-subscribers-to-mailchimp
Hi Tishan, unfortunately QuickTapSurvey doesn't support MailChimp Groups.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dmitry, QuickTapSurvey supports direct integration with MailChimp so you can push your data directly into MailChimp. Here's a link that describes the integration: http://support.quicktapsurvey.com/support/solutions/articles/199594-exporting-responses-email-subscribers-to-mailchimp