Dump items from Svpply onto Wanelo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'json' | |
require 'pp' | |
require 'open-uri' | |
require 'cgi' | |
require 'httparty' | |
affiliate_id = 'olenaw-20' | |
page = ARGV[0].to_i | |
# For building an api request | |
svvply = { | |
url: "https://svpply.com/api/v1/stores/7/products.json?filters%5Bgenders%5D%5B%5D=Gender&filters%5Bcategories%5D%5B%5D=Category&filters%5Bprices%5D%5B%5D=Price&access_token=1328899194%7C38c28874839b6285f0dd9c4427b1053c%7C51dbfa49818ed5436923ccb68c35a25e", | |
url_range: "&limit=%s&offset=%s", | |
offset: 100, | |
limit: page * 100 | |
} | |
# For making requests to wanelo site | |
# Going to make this more robust, with cookies and login | |
class Wanelo | |
include HTTParty | |
base_uri 'http://www.wanelo.com' | |
end | |
# Query SVPPLY for products | |
combined_url = svvply[:url] + (svvply[:url_range] % [svvply[:offset], svvply[:limit]]) | |
puts "Requesting SVVPLY API" | |
response = URI.parse(combined_url).read | |
json_response = JSON.parse(response) | |
# Grab the products | |
products = json_response['response']['products'] | |
puts "%s product(s) found" % products.size.to_s | |
links = "<h1>" + page.to_s + "</h1>" | |
products.each do |product| | |
# Rip out SVPPLY tag and drop in min | |
product['page_url'].gsub!('svpply01-20', affiliate_id) | |
# Specify the image we're gonna upload | |
product['olenaw_img_url'] = "https://s3.amazonaws.com/assets.svpply.com/large/%s.jpg?%s" % [product['id'], Time.now.to_i] | |
# What WANELO category should it be in? | |
if(product['category'] == 'apparel' || | |
product['category'] == 'accessories' || | |
product['category'] == 'shoes') | |
if(product['gender'] == 'female' || product['gender'] == 'neutral') | |
category = 110005 | |
elsif(product['gender'] == 'male') | |
category = 110004 | |
end | |
elsif(product['category'] == 'tech' || product['category'] == 'other') | |
category = 110003 | |
elsif(product['category'] == 'art' || product['category'] == 'home') | |
category = 110002 | |
elsif(product['category'] == 'media') | |
category = 110001 | |
end | |
# Compile the post data as observed in Charles | |
pdata = { | |
'contentaction' => 'productpreview', | |
'userId' => 381569, | |
'productTitle' => CGI.escape(product['page_title']), | |
'collectionId' => 3206607, | |
'collectionName' => 'My%20Wishlist', | |
'topCategoryId' => '-1', | |
'price' => product['price'], | |
'productUrl' => CGI.escape(product['page_url']), | |
'categoryId' => category, | |
'choosePhoto' => CGI.escape(product['olenaw_img_url']), | |
'imageUrls' => CGI.escape(product['olenaw_img_url']) + '^', | |
'imageType' => 'imported', | |
# Dead options | |
'productDescription' => '', 'uploadPhoto' => '', | |
'photoName' => '', 'tags' => '', 'reviewText' => '', 'noReview' => '', 'displayUrl' => '', | |
'imageUploadedByUrl' => '', 'productComment' => '', 'postToFacebook' => 0, 'postToTwitter' => 0 | |
} | |
pParams = pdata.map{|k,v| "#{k}=#{v}"}.join('&') | |
links = links + "<iframe style='width: 100%; height: 400px' src=\"http://www.wanelo.com/index.action?#{pParams}\"></iframe>" | |
end | |
page_s = page.to_s | |
file = File.new("links#{page_s}.html", "w") | |
file.write(links) | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment