Rakefile in ziptz-2.0.17 vs Rakefile in ziptz-2.1.0

- old
+ new

@@ -17,64 +17,8 @@ sh 'irb -r rubygems -I lib -r ziptz.rb' end desc 'Create ziptz db from zipcodes database' task :create_ziptz do - require 'yaml' - require 'active_record' - require 'tty-spinner' - - spinner = TTY::Spinner.new('[:spinner] Retrieving zip codes from database') - spinner.auto_spin - - db_config = YAML.safe_load(File.open('database.yml')) - ActiveRecord::Base.establish_connection(db_config) - - class ZipCode < ActiveRecord::Base - self.table_name = 'ZIPCodes' - self.primary_key = 'ZipCode' - - alias_attribute :zip_code, :ZipCode - alias_attribute :time_zone, :TimeZone - alias_attribute :day_light_saving, :DayLightSaving - end - - spinner = TTY::Spinner.new('[:spinner] :message') - spinner.update message: 'Retrieving zip codes from database' - data = {} - ZipCode.find_each do |zip| - next if zip.time_zone.blank? || zip.day_light_saving.blank? - - data[zip.zip_code] ||= {} - data[zip.zip_code][:tz] ||= zip.time_zone - data[zip.zip_code][:dst] ||= zip.day_light_saving - end - spinner.update message: "Retrieving zip codes from database (#{data.size} records)" - spinner.success - - spinner = TTY::Spinner.new('[:spinner] :message') - spinner.update message: 'Writing tz.data' - spinner.auto_spin - lines = data.map { |k, v| "#{k}=#{v[:tz]}" } - lines.sort! - File.open('data/tz.data', 'w') do |f| - lines.each { |line| f.puts line } - end - spinner.update message: "Writing tz.data (#{File.size('data/tz.data')} bytes)" - spinner.success - # puts File.size('data/tz.data').to_s - - spinner = TTY::Spinner.new('[:spinner] :message') - spinner.update message: 'Writing dst.data' - spinner.auto_spin - lines = data.map { |k, v| "#{k}=#{v[:dst] =~ /y/i ? 1 : 0}" } - lines.sort! - - File.open('data/dst.data', 'w') do |f| - lines.each { |line| f.puts line } - end - spinner.update message: "Writing dst.data (#{File.size('data/dst.data')} bytes)" - spinner.success -rescue StandardError - spinner && spinner.error - raise + require 'zip_code' + ZipCode.import end