Wilfred
12/06/2022, 10:14 AM[...]
created_product = Spree::Product.find_or_create_by(
name: name,
price: price,
description: description,
available_on: Time.current,
shipping_category: shipping_category,
tax_category: tax_category,
taxon_ids: [taxon_ids]
)
puts created_product.name
options = $browser.at_css("#productOverview_feature_div table")
values = []
options.css("tr").each_with_index do |row, index|
type = row.at_css("td:nth-of-type(1) span").text.strip
value = row.at_css("td:nth-of-type(2) span").text.strip
created_type = Spree::OptionType.find_or_create_by(
name: type,
presentation: type
)
# created_product.option_types << created_type.name
# created_product.save
# => ActiveRecord::AssociationTypeMismatch: Spree::OptionType(#74440) expected, got "Brand" which is an instance of String(#5020)
created_value = Spree::OptionValue.find_or_create_by(
name: value,
presentation: value,
option_type: created_type.name
)
puts "#{ created_type.name }: #{ created_value.name }"
values << created_value.name
end
created_product.variants.create(
option_values: [values],
sku: rand(100000)
)
created_product.save!
# => ActiveRecord::RecordInvalid: Validation failed: Option types is invalid, Variants is invalid, Variants including master is invalidmamhoff
12/06/2022, 12:55 PMWilfred
12/06/2022, 2:39 PMmamhoff
12/06/2022, 4:01 PMWilfred
12/06/2022, 6:59 PMWilfred
12/06/2022, 7:01 PMWilfred
12/06/2022, 7:28 PMFerrum::NodeNotFoundError: No node with given id found
/home/dev/wilfred/lib/tasks/amazon.rake:86:in `block (2 levels) in import_amazon'
/home/dev/wilfred/lib/tasks/amazon.rake:83:in `each'
/home/dev/wilfred/lib/tasks/amazon.rake:83:in `block in import_amazon'
/home/dev/wilfred/lib/tasks/amazon.rake:75:in `each'
/home/dev/wilfred/lib/tasks/amazon.rake:75:in `import_amazon'
/home/dev/wilfred/lib/tasks/amazon.rake:231:in `block (3 levels) in <main>'
/home/dev/wilfred/lib/tasks/amazon.rake:230:in `each'
/home/dev/wilfred/lib/tasks/amazon.rake:230:in `block (2 levels) in <main>'
Tasks: TOP => scrape:amazon
(See full trace by running task with --trace)
I also added some random user-agents: https://pastebin.com/crPYvE7e
I don't yet qualify for the Amazon Product Advertising API (I need an insane amount of traffic for that) so it's either scraping or manually copy/pasting.Wilfred
12/06/2022, 7:48 PMWilfred
12/06/2022, 7:49 PM