Sha256: 78dc8b945f129394d37280ac1f93849617e4a4ee7eb751bd5315474110b315e8
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
#!/usr/bin/env ruby require 'optparse' require 'methadone' require 'mailchimp' require 'erubis' require 'json' require 'mailchimp_exporter' class App include Methadone::Main include Methadone::CLILogging main do |mailchimp_api_key| mailchimp_api = Mailchimp::API.new(mailchimp_api_key) export_api = Mailchimp::Export.new(mailchimp_api_key) lib_folder = File.join(File.dirname(__FILE__),'..','lib') list_template_file = File.read("#{lib_folder}/mailchimp_exporter/list_template.erb") list_template = Erubis::Eruby.new(list_template_file) mailchimp_api.lists['data'].each do |list| puts "\t Extracting members from list: #{list['name']}" filename = options['output_folder'] + friendly_filename("#{list['id']}-#{list['name']}") + ".rdfa.html" members = export_api.list(id: list['id']).map {|member| JSON.parse(member)} File.open(filename, 'w') {|f| f.write(list_template.result(:list=>list, :members => members)) } puts "\t\t exported #{members.count} members to #{filename}" end end def self.friendly_filename(filename) filename.gsub(/[^\w\s_-]+/, '') .gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') .gsub(/\s+/, '_') end # Declare command-line interface here description "Export your MailChimp data (lists, campaigns) into standard formats like RDFa" options['output_folder'] = "./" on("--output_folder VAL","Folder to write exported data to") arg :mailchimp_api_key, "Your MailChimp API key (including datacenter, in format: '{key}-{dc}')" version MailchimpExporter::VERSION use_log_level_option go! end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mailchimp_exporter-0.0.3 | bin/mailchimp_exporter |