Skip to content

Instantly share code, notes, and snippets.

@kyletcarlson kyletcarlson/bluemix.rb
Last active Sep 8, 2017

Embed
What would you like to do?
require 'asin'
require 'awesome_print'
ASIN::Configuration.configure do |config|
config.associate_tag = 'carlscorn-20'
config.key = 'AKIAJHAI7AL2VNXA4JWA'
config.secret = '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'
end
# B01NCQDDVH GUN HOLSTER (single category)
# B01J9IRK56 gripsticks (multiple categories)
# B001AVQHTG sanar colon cleanse
asins = [
'B001AVQHTG'
]
title_mashup = ""
client = ASIN::Client.instance
items = client.lookup(asins, ResponseGroup: [:Small, :Similarities, :BrowseNodes])
nodes_list = []
puts "\n\n\n"
items.each do |item|
ap item
# handle if there aren't any similar items
unless item.similar_products.similar_product.nil?
# collect all ASINs and Titles
item.similar_products.similar_product.each do |similar|
asins << similar['ASIN']
title_mashup += similar['Title'] + " "
end
#### Add all nodes from the array
if item.browse_nodes.browse_node.kind_of?(Array)
item.browse_nodes.browse_node.each do |node|
ap node['BrowseNodeId']
nodes_list << node['BrowseNodeId']
puts "\n\n"
end
ap nodes_list
end
end
if item.browse_nodes.browse_node.kind_of?(Hashie::Mash)
ap item.browse_nodes.browse_node.first[1]
nodes_list << item.browse_nodes.browse_node.browse_node_id
end
#### ONLY TAKING LAST (MOST SPECIFIC?) NODE of nodes_list[] array
top_sellers_node = client.browse_node(nodes_list[-1], :ResponseGroup => [:TopSellers]).first['top_sellers']['top_seller']
top_sellers_node.each do |item|
# ap item['ASIN']
# ap item['Title']
asins << item['ASIN']
title_mashup += item['Title'] + " "
end
#### Grab item Features (bullet points) of first 10 ASINs in the list
# ap asins.uniq.take(10)
asins.take(50).each do |asin|
# ap asin
sleep(0.90)
item = client.lookup(asin, ResponseGroup: [:Medium])
unless ap item.first.item_attributes.feature.kind_of?(REXMLUtiliyNodeString)
ap item.first.item_attributes.feature.each do |feature|
title_mashup << feature
end
end
end
end
ap title_mashup + "\n\n"
# =================
# keyword generator
# =================
WORD_COUNTS = title_mashup.split(" ").each_with_object(Hash.new(0)) { |word,counts| counts[word] += 1 }
.sort_by { |key, value| value }.reverse
word_paragraph = ""
WORD_COUNTS.each do |word|
if word[0].length > 3
word_paragraph += word[0] + " "
end
end
# puts word_paragraph + "\n\n"
clipped_keyword_list = ""
word_paragraph.split(" ").each do |word|
if clipped_keyword_list.length + word.length <= 249
clipped_keyword_list += word + " "
end
end
puts "\n\n"
last_index_of_space = clipped_keyword_list.rindex(" ")
clipped_keyword_list = clipped_keyword_list[0..last_index_of_space - 1]
ap clipped_keyword_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.