class Zips < Thor desc 'load [full path to zip_code file]', "Load geonames zips with lat longs into Redis" def load(zip_code_file=nil) require './config/environment' raise "Can't find that zip code file '#{zip_code_file}'" unless File.exist? zip_code_file ZipCode.connection.execute "TRUNCATE `zip_codes`" st = ZipCode.connection.raw_connection.prepare "INSERT IGNORE INTO `zip_codes` (`zip_code`, `city`, `state_short`, `lat`, `lng`) VALUES (?, ?, ?, ?, ?)" File.readlines(zip_code_file).each_with_index do |line| data = line.force_encoding("UTF-8").split("\t") st.execute(data[1],data[2],data[4], data[9], data[10]) end st.close end end