<commit_before>namespace :products do

  desc "Import products to spree database."
  task :to_rodamoto => :environment do
    require 'my_import_products'
    articulos = DBF::Table.new("/home/jose/Documentos/rodamoto/articulo.dbf")
    for i in 1..5 do
      @product = Spree::Product.new
      @product.name = articulos.find(i).attributes["nombre"]
      @product.permalink = articulos.find(i).attributes["nombre"].downcase.gsub(/\s+/, '-').gsub(/[^a-zA-Z0-9_]+/, '-')
      @product.count_on_hand = 5
      @product.sku = articulos.find(i).attributes["codigo"]
      @product.price = articulos.find(i).attributes["pvp3"]
      @product.cost_price = articulos.find(i).attributes["pvp1"]
      ancho = articulos.find(i).attributes["ancho"]
      perfil = articulos.find(i).attributes["perfil"]
      llanta = articulos.find(i).attributes["llanta"]
      ic = articulos.find(i).attributes["ic"]
      vel = articulos.find(i).attributes["vel"]
      fr = articulos.find(i).attributes["fr"]
      tttl = articulos.find(i).attributes["tttl"]
      
      @product.tire_width_id = (ancho == "" ? ancho : Spree::TireWidth.find_by_name(ancho.to_s).id)
      @product.tire_profile_id = (perfil == "" ? perfil : Spree::TireProfile.find_by_name(perfil.to_s).id)
      @product.tire_innertube_id = (llanta == "" ? llanta : Spree::TireInnertube.find_by_name(llanta.to_s).id)
      @product.tire_ic_id = (ic == "" ? ic : Spree::TireIc.find_by_name(ic.to_s).id)
      @product.tire_speed_code_id = (vel == "" ? vel : Spree::TireSpeedCode.find_by_name(vel.to_s).id)
      @product.tire_fr_id = (fr == "" ? fr : Spree::TireFr.find_by_name(fr.to_s).id)
      @product.tire_tttl_id = (tttl == "" ? tttl : Spree::TireTttl.find_by_name(tttl.to_s).id)
      @product.taxons << MyImportProducts::set_catalog(articulos.find(i).attributes["clasub"], articulos.find(i).attributes["clatipart"], articulos.find(i).attributes["clacat"])
      @product.taxons << MyImportProducts::set_brand(articulos.find(i).attributes["clamar"])
      if @product.save!
        puts "grabado articulo" + @product.name
      end      
    end
  end
  
  desc "Make a txt/csv file."
  task :to_csv  => :environment do
    require 'my_import_products'
    @dir = Dir.glob(File.join(Rails.root, "vendor", "exports", "products" ))
    articulos = DBF::Table.new("/home/jose/Documentos/rodamoto/articulo.dbf")
    CSV.open("#{Rails.root}/vendor/exports/products/products-#{DateTime.now.strftime('%H-%M-%S-%d-%m-%Y')}.csv", "w") do |csv|
      csv << ["product", "", "sku", "name", "permalink", "quantity", "description", "prototype", "category", "gender", "tax_category", "shipping_category", "deleted_at", "shipping_time", "style", "frame_width", "frame_type", "frame_shape", "bridge_width", "eye_size", "arm_length", "image", "image2", "image3", "meta_description", "meta_keywords", "delete", "price", "weight", "height", "width", "depth", "cost_price"]
      articulos.each do |articulo|
        csv << ["Product", 
        "",
        articulo.codigo, 
        articulo.nombre, 
        articulo.nombre.downcase.gsub(/\s+/, '-').gsub(/[^a-zA-Z0-9_]+/, '-'), 
        articulo.exmin, 
        "", 
        "prototype", 
        "category", 
        "gender", 
        "", 
        "",<commit_msg>mejoras en import task<commit_after>namespace :products do

  desc "Import products to spree database."
  task :to_rodamoto => :environment do
    require 'my_import_products'
    articulos = DBF::Table.new("/home/jose/Documentos/rodamoto/articulo.dbf")
    for i in 1..5 do
      @product = Spree::Product.new
      @product.name = articulos.find(i).attributes["nombre"]
      @product.permalink = articulos.find(i).attributes["nombre"].downcase.gsub(/\s+/, '-').gsub(/[^a-zA-Z0-9_]+/, '-')
      @product.count_on_hand = 5
      @product.sku = articulos.find(i).attributes["codigo"]
      @product.price = articulos.find(i).attributes["pvp3"]
      @product.cost_price = articulos.find(i).attributes["pvp1"]
      ancho = articulos.find(i).attributes["ancho"]
      perfil = articulos.find(i).attributes["perfil"]
      llanta = articulos.find(i).attributes["llanta"]
      ic = articulos.find(i).attributes["ic"]
      vel = articulos.find(i).attributes["vel"]
      fr = articulos.find(i).attributes["fr"]
      tttl = articulos.find(i).attributes["tttl"]
      
      @product.tire_width_id = (ancho == "" ? ancho : Spree::TireWidth.find_by_name(ancho.to_s).id)
      @product.tire_profile_id = (perfil == "" ? perfil : Spree::TireProfile.find_by_name(perfil.to_s).id)
      @product.tire_innertube_id = (llanta == "" ? llanta : Spree::TireInnertube.find_by_name(llanta.to_s).id)
      @product.tire_ic_id = (ic == "" ? ic : Spree::TireIc.find_by_name(ic.to_s).id)
      @product.tire_speed_code_id = (vel == "" ? vel : Spree::TireSpeedCode.find_by_name(vel.to_s).id)
      @product.tire_fr_id = (fr == "" ? fr : Spree::TireFr.find_by_name(fr.to_s).id)
      @product.tire_tttl_id = (tttl == "" ? tttl : Spree::TireTttl.find_by_name(tttl.to_s).id)
      @product.taxons << MyImportProducts.set_catalog(articulos.find(i).attributes["clasub"], articulos.find(i).attributes["clatipart"], articulos.find(i).attributes["clacat"])
      @product.taxons << MyImportProducts.set_brand(articulos.find(i).attributes["clamar"])
      if @product.save!
        puts "grabado articulo" + @product.name
      end      
    end
  end
  
  desc "Make a txt/csv file."
  task :to_csv  => :environment do
    require 'my_import_products'
    @dir = Dir.glob(File.join(Rails.root, "vendor", "exports", "products" ))
    articulos = DBF::Table.new("/home/jose/Documentos/rodamoto/articulo.dbf")
    CSV.open("#{Rails.root}/vendor/exports/products/products-#{DateTime.now.strftime('%H-%M-%S-%d-%m-%Y')}.csv", "w") do |csv|
      csv << ["product", "", "sku", "name", "permalink", "quantity", "description", "prototype", "category", "gender", "tax_category", "shipping_category", "deleted_at", "shipping_time", "style", "frame_width", "frame_type", "frame_shape", "bridge_width", "eye_size", "arm_length", "image", "image2", "image3", "meta_description", "meta_keywords", "delete", "price", "weight", "height", "width", "depth", "cost_price"]
      articulos.each do |articulo|
        csv << ["Product", 
        "",
        articulo.codigo, 
        articulo.nombre, 
        articulo.nombre.downcase.gsub(/\s+/, '-').gsub(/[^a-zA-Z0-9_]+/, '-'), 
        articulo.exmin, 
        "", 
        "prototype", 
        "category", 
        "gender", 
        "", 
        "",
{'fraction_non_alphanumeric': 0.18933456277854618, 'fraction_numerical': 0.003380974335331182, 'mean_word_length': 3.6090651558073654, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1640608', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2395, 'n_words': 327}