Commit c1144e64 by Tan Phat Nguyen Committed by Tan Phat Nguyen

Dev Amazon get data

parent 9a67c835
......@@ -135,7 +135,7 @@ GEM
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
kgio (2.9.2)
listen (2.7.11)
listen (2.8.0)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
......@@ -220,7 +220,7 @@ GEM
responders (2.0.2)
railties (>= 4.2.0.alpha, < 5)
ruby-progressbar (1.7.0)
sass (3.4.7)
sass (3.4.8)
sass-rails (5.0.0.beta1)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2)
......
......@@ -31,9 +31,9 @@ params = {
rg = %w(ItemAttributes Images EditorialReview).join(',')
@res = req.item_search(query: {
'ItemSearch.Shared.SearchIndex' => 'All',
'ItemSearch.Shared.Keywords' => 'Grow Rich',
'ItemSearch.Shared.Keywords' => '*',
'ItemSearch.Shared.ResponseGroup' => rg,
'ItemSearch.SearchIndex' => 'Toys',
'ItemSearch.SearchIndex' => 'Books',
'ItemSearch.1.ItemPage' => 1,
'ItemSearch.2.ItemPage' => 2
})
......
......@@ -23,6 +23,14 @@ class ImageUploader < CarrierWave::Uploader::Base
%w(jpg jpeg gif png)
end
version :thumb do
process :resize_to_fill => [140,140]
end
def default_url
"fallback/" + [thumb, "default_photo.png"].compact.join('_')
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
......
......@@ -3,4 +3,5 @@
<h2>Count: <%= @result.length %></h2>
<h2>Add_new: <%= @add_new.length %></h2>
<%= @ret %> <br>
<h2>Item 0: </h2>
<%= @add_new %>
\ No newline at end of file
<h1>Amazon#welcome</h1>
<p>Find me in app/views/amazon/welcome.html.erb</p>
<%= @res.to_h %>
......@@ -6,6 +6,6 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
%w(Books Toys Clothing DVD Magazine).each do |category|
%w(Books Toys OutdoorLiving Appliances Magazines).each do |category|
Category.create(name: category)
end
......@@ -7,5 +7,55 @@ namespace :db do
def import_products
puts 'Call import_products method'
req = Vacuum.new
req.configure(
aws_access_key_id: 'AKIAI4FGZR4YFCAP4DVQ',
aws_secret_access_key: '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',
associate_tag: 'tag'
)
rg = %w(ItemAttributes Images EditorialReview).join(',')
categories = Category.all
var_category = {'Books' => '1000', 'Toys' => '165793011', 'OutdoorLiving' => '286168',
'Appliances' => '2619525011', 'Magazines' => '599872'}
categories.each do |category|
[1, 7].each do |page_number|
@res = req.item_search(query: {
'ItemSearch.Shared.Condition' => 'New',
'ItemSearch.Shared.BrowseNode' => var_category[category.name],
'ItemSearch.Shared.ResponseGroup' => rg,
'ItemSearch.SearchIndex' => category.name,
'ItemSearch.1.ItemPage' => page_number,
'ItemSearch.2.ItemPage' => 10
})
@add_new = []
@res.to_h["ItemSearchResponse"].to_h["Items"].to_a.each do |item|
item.to_h["Item"].to_a.each do |value|
book_tmp = value.to_h
@add_new.push(details: book_tmp['DetailPageURL'], image: book_tmp['LargeImage'],
item: book_tmp['ItemAttributes'], editor: book_tmp['EditorialReviews'])
end
end
@add_new.each do |item_res|
item_product = Product.new
item_product.name = item_res[:item]['Title']
if item_res[:item].has_key?('ListPrice')
item_product.price = item_res[:item]['ListPrice']['FormattedPrice'][1..-1]
else
item_product.price = item_res[:item]['TradeInValue']['FormattedPrice'][1..-1]
end
if item_res[:editor]['EditorialReview'].kind_of?(Array)
item_product.description = item_res[:editor]['EditorialReview'][0]['Content']
else
item_product.description = item_res[:editor]['EditorialReview']['Content']
end
# item_product[:remote_photo_url] = item_res[:image]['URL']
category.products << item_product
puts 'OK'
end
end
category.save
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment