Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tan Phat Nguyen
venshop
Commits
fbc9fcb1
Commit
fbc9fcb1
authored
Nov 17, 2014
by
Tan Phat Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Amazon get item
parent
c1144e64
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
21 deletions
+19
-21
db/seeds.rb
+1
-1
lib/tasks/db.rake
+18
-20
No files found.
db/seeds.rb
View file @
fbc9fcb1
...
...
@@ -6,6 +6,6 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
%w(Books
Toys
OutdoorLiving Appliances Magazines)
.
each
do
|
category
|
%w(Books
HealthPersonalCare
OutdoorLiving Appliances Magazines)
.
each
do
|
category
|
Category
.
create
(
name:
category
)
end
lib/tasks/db.rake
View file @
fbc9fcb1
...
...
@@ -17,45 +17,43 @@ namespace :db do
rg
=
%w(ItemAttributes Images EditorialReview)
.
join
(
','
)
categories
=
Category
.
all
var_category
=
{
'Books'
=>
'1000'
,
'
Toys'
=>
'16579301
1'
,
'OutdoorLiving'
=>
'286168'
,
var_category
=
{
'Books'
=>
'1000'
,
'
HealthPersonalCare'
=>
'376093
1'
,
'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.Shared.ResponseGroup'
=>
'Large'
,
'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
|
@res
=
@res
.
to_h
@res
[
'ItemSearchResponse'
][
'Items'
][
0
][
'Item'
].
each
do
|
item
|
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
]
puts
item
[
'ItemAttributes'
][
'Title'
]
item_product
.
name
=
item
[
'ItemAttributes'
][
'Title'
]
item_product
.
price
=
item
[
'ItemAttributes'
][
'ListPrice'
][
'FormattedPrice'
][
1
..-
1
]
if
item
[
'EditorialReviews'
][
'EditorialReview'
].
kind_of?
(
Array
)
item_product
.
description
=
item
[
'EditorialReviews'
][
'EditorialReview'
][
0
][
'Content'
]
else
item_product
.
price
=
item_res
[
:item
][
'TradeInValue'
][
'FormattedPrice'
][
1
..-
1
]
item_product
.
description
=
item
[
'EditorialReviews'
][
'EditorialReview'
][
'Content'
]
end
if
item_res
[
:editor
][
'EditorialReview'
].
kind_of?
(
Array
)
item_product
.
description
=
item_res
[
:editor
][
'EditorialReview'
][
0
][
'Content'
]
if
item
.
has_key?
(
'MediumImage'
)
#item_product[:remote_photo_url] = item['MediumImage']['URL']
else
if
item
[
'ImageSets'
][
'ImageSet'
].
kind_of?
(
Array
)
#item_product[:remote_photo_url] = item['ImageSets']['ImageSet'][0]['MediumImage']['URL']
else
item_product
.
description
=
item_res
[
:editor
][
'EditorialReview'
][
'Content'
]
#item_product[:remote_photo_url] = item['ImageSets']['ImageSet']['MediumImage']['URL']
end
end
# item_product[:remote_photo_url] = item_res[:image]['URL']
category
.
products
<<
item_product
puts
'OK'
end
end
category
.
save
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment