Skip to content

Instantly share code, notes, and snippets.

@rwoeber
Created December 23, 2010 08:10
Show Gist options
  • Select an option

  • Save rwoeber/752725 to your computer and use it in GitHub Desktop.

Select an option

Save rwoeber/752725 to your computer and use it in GitHub Desktop.
generate DHL recipies from orders
require 'iconv'
require 'csv'
UTF8_ISO_CONVERTER = Iconv.new('ISO-8859-1', 'utf-8')
shipping_time = Time.now
ready_to_ship_orders = Order.find(:all, :conditions => Order::State::ATTRIBUTE_CONDITIONS[Order::State::IN_SHIPPING])
filename => "/tmp/dhl_#{shipping_time.to_formatted_s(:jdate)}_#{shipping_time.to_formatted_s(:jtime)}.txt"
CSV::Writer.generate(output = "","|") do |csv|
ready_to_ship_orders.each_with_index do |order,i|
order.dhl_fields(i+1,shipping_time).each{|line| csv << line}
end
end
open(filename,'w'){|f| f.puts UTF8_ISO_CONVERTER.iconv(output)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment