Skip to content

Instantly share code, notes, and snippets.

@arjunblj
Forked from bytesizedpcs/supreme_README.txt
Created January 13, 2017 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjunblj/9a7cf5464ae371add789f82971b85123 to your computer and use it in GitHub Desktop.
Save arjunblj/9a7cf5464ae371add789f82971b85123 to your computer and use it in GitHub Desktop.
#!/bin/env/ python2
# Version 1.2.0
# Rewrite
# Simple program to checkout in supreme
# Adding multiprocessing and proxy support
# Made by: @Imguavamane on Twitter
import sys
import time
import requests
import signal
import multiprocessing
from datetime import datetime
checkout_url = "https://www.supremenewyork.com/checkout.json"
original_headers = {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B350 Safari/8536.25'
}
checkout_headers = {
'Host': 'www.supremenewyork.com',
'If-None-Match': '"*"',
'Accept': 'application/json',
'Proxy-Connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-us',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'http://www.supremenewyork.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257',
'Referrer': 'http://www.supremenewyork.com/mobile'
}
class Timeout:
class Timeout(Exception):
pass
def __init__(self, sec):
self.sec = sec
def __enter__(self):
signal.signal(signal.SIGALRM, self.raise_timeout)
signal.alarm(self.sec)
def __exit__(self, *args):
signal.alarm(0) # disable alarm
def raise_timeout(self, *args):
raise Timeout.Timeout()
def to_log(*msg):
timestamp = str(datetime.now())
string = [str(x) for x in msg]
print timestamp, ' '.join(string)
def get_proxy():
proxy_dict = {
}
return proxy_dict
def get_running_information():
to_log(":: Supreme Python Bot: 1.2.0, Copyright (C) 2016 @ImGuavamane")
to_log(":: This is free software, and you are welcome to redistribute it.")
to_log(":: These lines must be present in any and every redistributed version of this code. ")
to_log(":: Failure to do this will be a breach of GNU v3 License Agreement.")
sleep_time = raw_input("How long to wait for ghost checkout?: ")
try:
int(sleep_time)
tries = raw_input("How many carts do you want?: ")
except ValueError:
to_log("You must enter a number, 0 if none!")
try:
int(tries)
keyword = raw_input("Enter product name: ").title()
except ValueError:
to_log("You must enter a number, 0 if none!")
color = raw_input("Enter color: ").title()
size = raw_input("Enter size: ").title()
return sleep_time, keyword, color, size, tries
def get_json_data(url):
try:
with Timeout(6):
r = requests.get(url, headers=original_headers)
if not r.status_code // 100 == 2:
to_log("Error: Unexpected response {}".format(r))
to_log("::", r.status_code)
json_data = r.json()
return json_data
except requests.exceptions.RequestException as e:
print e
sys.exit(0)
def look_up_items(json_data, keyword):
to_log(":: Searching through stock...")
id_num = 0
for i in range(len(json_data[u'products_and_categories'].values())):
for j in range(len(json_data[u'products_and_categories'].values()[i])):
item = json_data[u'products_and_categories'].values()[i][j]
name = str(item[u'name'].encode('ISO-8859-1', 'ignore'))
if keyword in name:
my_product = name
id_num = str(item[u'id'])
json_url = "http://www.supremenewyork.com/shop/" + id_num + ".json"
to_log("::", name, "id_num:", id_num, "found (MATCHING ITEM FOUND)")
return my_product, id_num, json_url
if id_num == 0:
for i in range(1):
to_log(":: Waiting", 1 - i, "seconds...")
time.sleep(1)
json_data = get_json_data("http://www.supremenewyork.com/mobile_stock.json")
look_up_items(json_data, keyword)
def look_up_size(my_product, id_num, json_url, color, size):
try:
to_log(":: Selecting", my_product, '(', id_num, ')')
data = get_json_data(json_url)
for num_cw in data['styles']:
if color in num_cw['name'].title():
for sizes in num_cw['sizes']:
if str(sizes['name'].title()) == size:
variant = str(sizes['id'])
cw = num_cw['name']
to_log(":: Selecting size:", sizes['name'] + ' in ' + cw, variant)
return variant
elif str(sizes['name'].title()) == 'N/A':
cw = num_cw['name']
variant = str(data['styles'][0]['sizes'][len(data['styles'][0]['sizes']) - 1]['id'])
to_log(":: Selecting default size:", sizes['name'] + ' in ' + cw, variant)
return variant
except ValueError as e:
to_log(e)
def add_to_cart_and_checkout(variant, id_num, sleep_time):
session = requests.Session()
add_url = "http://www.supremenewyork.com/shop/" + id_num + "/add.json"
add_headers = {
'Host': 'www.supremenewyork.com',
'Accept': 'application/json',
'Proxy-connection': 'keep-alive',
'X-Requested-Width': 'XMLHttpRequest',
'Accept-Language': 'en-us',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'http://www.supremenewyork.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257',
'Referer': 'http://www.supremenewyork.com/mobile',
'Content-Length': '16'
}
add_payload = {
'size': str(variant),
'qty': 1
}
checkout_payload = {
'store_credit_id': '',
'from_mobile': '1',
'cookie-sub': '%7B%22' + str(variant) + '%22%3A1%7D', # cookie-sub: eg. {"VARIANT":1} urlencoded
'same_as_billing_address': '1',
'order[billing_name]': 'anon mous', # FirstName LastName
'order[email]': 'anon@mailinator.com', # email@domain.com
'order[tel]': '999-999-9999', # phone-number-here
'order[billing_address]': '123 Seurat lane', # your address
'order[billing_address_2]': '',
'order[billing_zip]': '90210', # zip code
'order[billing_city]': 'Beverly Hills', # city
'order[billing_state]': 'CA', # state
'order[billing_country]': 'USA', # country
'store_address': '1',
'credit_card[type]': 'visa', # master or visa
'credit_card[cnb]': '9999 9999 9999 9999', # credit card number
'credit_card[month]': '01', # expiration month
'credit_card[year]': '2026', # expiration year
'credit_card[vval]': '123', # cvc/cvv
'order[terms]': '0',
'order[terms]': '1'
}
to_log(":: Adding product to cart...", variant)
try:
add_resp = session.post(add_url, data=add_payload, headers=add_headers)
to_log("~~", add_resp)
if not add_resp.status_code // 100 == 2:
to_log("Error: Unexpected response {}".format(add_resp))
except requests.exceptions.HTTPError as e:
to_log("Error: {}".format(e))
session.close()
for i in range(int(sleep_time)):
to_log(":: Sleeping for to avoid ghost checkout...", int(sleep_time) - i)
sys.stdout.flush()
time.sleep(1)
to_log("~~ Checking out via", checkout_url)
try:
to_log(":: Checking out...")
checkout_resp = session.post(checkout_url, data=checkout_payload, headers=checkout_headers)
if not checkout_resp.status_code // 100 == 2:
to_log("Error: Unexpected response {}".format(add_resp))
except requests.exceptions.HTTPError as e:
to_log("Error: {}".format(e))
session.close()
except ValueError as e:
to_log("Error: {}".format(e))
session.close()
else:
to_log(":: Error checking out ::", checkout_resp.json()['errors'])
session.close()
to_log(":: Checked out", variant + ' (' + id_num + ')')
session.close()
def start_url_process(sleep_time, keyword, color, size):
json_data = get_json_data("http://www.supremenewyork.com/mobile_stock.json")
my_product, id_num, json_url = look_up_items(json_data, keyword)
to_log("~~ MAIN ~~", my_product, id_num, json_url)
variant = look_up_size(my_product, id_num, json_url, color, size)
add_to_cart_and_checkout(variant, id_num, sleep_time)
def main():
jobs = []
sleep_time, keyword, color, size, tries = get_running_information()
for i in range(int(tries)):
to_log(":: Starting", str(tries), "processes...")
process = multiprocessing.Process(target=start_url_process(sleep_time, keyword, color, size))
jobs.append(process)
process.start()
if __name__ == "__main__":
main()
Setup instructions:
** I WOULD HIGHLY RECOMMEND SETTING THIS UP IN A VM**
1. Install Homebrew
2. Install Python with homebrew
3. Install pip with homebrew
4. Install requests with pip
5. Install requests[security] with pip
6. If necessary, install/update OpenSSL with homebrew
7. Download the script, save it anywhere
8. Edit you Credit Card information in the scirpt (this is safe, all information is saved on YOUR computer)
9. run the scirpt (python supreme_python_001.py)
10. Answer the questions and hit enter after each one
11. Cop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment