Skip to content

Instantly share code, notes, and snippets.

@tiegz
Last active July 25, 2021 19:10
Show Gist options
  • Save tiegz/4a90482eca996cd298ef to your computer and use it in GitHub Desktop.
Save tiegz/4a90482eca996cd298ef to your computer and use it in GitHub Desktop.
uniqlo scraper
require 'json'
require 'pp'
class UniqloProductFetcher
attr_accessor :json
# eg 135779 is pocketable shorts
def initialize(product_id: "135779")
@product_id = product_id
end
def fetch
response = `curl 'http://www.uniqlo.com/us/store/gcx/getProductInfo.do?format=json&product_cd=#{@product_id}&_=1438114287430' -H 'Cookie: JSESSIONID=D0F5E42057CE22CF682664F5B748D5FF; DISPSITE=PC; VIEWED_ITEM=135779; mmcore.tst=0.560; mmid=1072573136%7CAgAAAApAD6jMOgwAAA%3D%3D; mmcore.pd=-204711399%7CAgAAAAoBQkAPqMw6DIYlqroBAM0523+Il9JIDwAAAEN/4HCIl9JIAAAAAAEAAAD/////AA53d3cuZ29vZ2xlLmNvbQQ6DAEAAAAAAAAAAAAAuJQAALiUAAD/////AQB3NgAAAD7NvZI6DAD/////AToMOgz//wIAAAEAAAAAAqSJAADb2AAAiJkAANbzAAABuJQAAAIAAAAAAAABRQ%3D%3D; mmcore.srv=nycvwcgus06; AWSELB=0189B32CE2E752CCA1C011F3815672DD77C927FE476EB33E88362891426600821E3373042654E7878E018EE3C26646CDC304D16982E47B6315C205365DDE5E690016A7E8; _dc_gtm_UA-494938-36=1; __rutmc=269552309; __rutmb=269552309; _gat_UA-494938-36=1; riTrack_WRSID=1438114263735872375; __rfcs=%7B%22b%22%3A24721%2C%22t%22%3A198.6540355682373%2C%22sp%22%3A995539.805845359%2C%22c%22%3A1%7D; _gat=1; BIGipServerpool-gds-uspc=830263562.20480.0000; tfcAnalytics=d7df3574-830b-44ab-9f3c-3dad7102964f; tfcga=GA1.2.537746363.1438114266; _tfcUserCookie=V5|unk_005331cd-512d-41a6-93ff-b5c5a57f5a2d|1469563866; tfcUserSettings=; _gat_tfcua1=1; tfcUserVisit=tfc-fitrec-product=1; testVersion=versionA; __rutma=269552309-4lj5t0ya-bwyv-4q59-y07o-nfex5ip5vfrd-1438114262217.1438114262217.1438114262217.1.2; __rref=https%3A%2F%2Fwww.google.com%2F; __rcmp=n%3D_gc%2Cf%3Dgc%2Cs%3D1%2Cc%3D683%2Ctr%3D100%2Crn%3D816%2Cts%3D20150728.2011%2Cd%3Dpc%3Bn%3Drw%2Cf%3Drw%2Cs%3D1%2Cc%3D339%2Ct%3D20141006.0807%3Bn%3Dsb%2Cf%3Dsb%2Cs%3D1%2Cc%3D340%2Ct%3D20141006.0809%3Bn%3Drg%2Cf%3Drg%2Cs%3D1%2Cc%3D341%2Ct%3D20141006.0810; _ga=GA1.2.965764063.1438114262' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,ja;q=0.6' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36' -H 'Accept: text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01' -H 'Referer: http://www.uniqlo.com/us/product/men-pocketable-shorts-135779.html' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed`
@json = JSON.parse response
@json
end
def available?
fetch
json["stock_cnt_l1"].to_i > 0
end
end
# Running form shell: ruby uniqlo_checker.rb > uniqlo_checker.log &
$: << "."
require 'open-uri'
require 'json'
require 'uniqlo'
puts "Starting..."
loop do
puts "Checking..."
# pocketable shorts
product_id = "135779"
product_name = "Pocketable+shorts"
fetcher = UniqloProductFetcher.new(product_id: product_id)
twilio_account_id = "xxx"
twilio_account_secret = "xxx"
twilio_phone = "5555555555"
notification_phone = "5555555555"
puts "#{Time.now.to_s} -- #{product_id}"
if fetcher.available?
cmd = %Q!curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/#{twilio_account_id}/SMS/Messages.xml' \
-d 'From=%2B1#{twilio_phone}' \
-d 'To=%2B1#{notification_phone}' \
-d 'Body=#{product_name}+are+available,+man' \
-u #{twilio_account_id}:#{twilio_account_secret}!
puts `#{cmd}`
puts
sleep 5
end
STDOUT.flush
sleep 60 * 15
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment