Created
October 4, 2016 03:37
-
-
Save bytesizedpcs/9e79a0f296cef2b7f27cb0c1c8c2cf4e to your computer and use it in GitHub Desktop.
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
#!/bin/env/ python2.7 | |
# Version 1.0.0 | |
# Simple program to checkout in supreme | |
# adding multiprocessing and proxy support | |
import sys | |
import json | |
import time | |
import requests | |
import urllib2 | |
from datetime import datetime | |
# function to get current time | |
# necessary for debugging and seeing how fast everything is | |
def utcToETC(): | |
currenttime = datetime.now() | |
return str(currenttime) + ' EST' | |
# get the information necessary | |
def getInformation(): | |
# getlast = raw_input("Would you like to get the last size, and color if available? [Y/N]: ").upper() | |
sleepTime = int(raw_input("How long to wait for ghost checkout?: ")) | |
poll = int(raw_input("Enter Polling Interval (seconds): ")) | |
keyword = raw_input("Enter product name: ").title() | |
color = raw_input("Enter color(s): ").title() | |
size = raw_input("Enter size(s): ").title() | |
return sleepTime, poll, keyword, color, size | |
# get json data from supreme, or any url really | |
# Needs url | |
# returns jsondata | |
def getJsonData(url): | |
try: | |
req = urllib2.Request(url) | |
except requests.exceptions.RequestException as e: | |
print e | |
sys.exit(0000) | |
else: | |
req.add_header('User-Agent', | |
"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") | |
response = urllib2.urlopen(req) | |
jsondata = json.loads(response.read()) | |
return jsondata | |
# not working | |
def getJsonDataWithProxy(url): | |
proxy = { | |
'http': '52.43.200.172:1080' | |
} | |
try: | |
proxy = urllib2.ProxyHandler(proxy) | |
opener = urllib2.build_opener(proxy) | |
urllib2.install_opener(opener) | |
req = urllib2.Request(url) | |
except requests.exceptions.RequestException as e: | |
print e | |
sys.exit(7) | |
else: | |
req.add_header('User-Agent', | |
"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") | |
response = urllib2.urlopen(req) | |
jsondata = json.loads(response.read()) | |
return jsondata | |
# Look up item in json data | |
# Wanting to be able to cart multiple in the future using proxies | |
# Needs JSON data, keyword, poll | |
# Returns myProduct, ID, jsonUrl | |
def lookupItems(jsondata, keyword, poll): | |
ID = 0 | |
while(ID == 0): | |
time.sleep(poll) | |
print utcToETC(), ":: Parsing page..." | |
for i in range(len(jsondata[u'products_and_categories'].values())): | |
for j in range(len(jsondata[u'products_and_categories'].values()[i])): | |
item = jsondata[u'products_and_categories'].values()[i][j] | |
name = str(item[u'name'].encode('ascii', 'ignore')) | |
if keyword in name: | |
myProduct = name | |
ID = str(item[u'id']) | |
jsonUrl = "http://www.supremenewyork.com/shop/" + ID + ".json" | |
print utcToETC(), "::", name, ID, "found (MATCHING ITEM DETECTED)" | |
return myProduct, ID, jsonUrl | |
# Look up the size and color in the json data | |
# Needs myProduct, id, json url, color, size | |
# returns variant, cw, found, ID | |
def lookupSize(myProduct, ID, jsonUrl, color, size): | |
found = 0 | |
while found == 0: | |
print utcToETC(), ":: Selecting", myProduct, '(', ID, ')' | |
data = getJsonData(jsonUrl) | |
for numCW in data['styles']: | |
if color in numCW['name'].title(): | |
for sizes in numCW['sizes']: | |
if str(sizes['name'].title()) == size: | |
found = 1 | |
variant = str(sizes['id']) | |
cw = numCW['name'] | |
print utcToETC(), ":: Selecting size: ", sizes['name'], '(', cw, ')', '(', variant, ')' | |
return variant, cw, found, ID | |
# Add the item to your cart | |
# Needs variant, cw, id | |
# returns addResp | |
def addToCart(variant, cw, ID): | |
session = requests.Session() | |
addUrl = "http://www.supremenewyork.com/shop/" + ID + "/add.json" | |
addHeaders = { | |
'Host': 'www.supremenewyork.com', | |
'Accept': 'application/json', | |
'Proxy-connection': 'keep-alive', | |
'X-Requested-Width': 'XMLHttpRequest', | |
'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' | |
} | |
addPayload = { | |
'size': str(variant), | |
'qty': 1 | |
} | |
print utcToETC(), ":: Adding product to cart..." | |
addResp = session.post(addUrl, data=addPayload, headers=addHeaders) | |
print utcToETC() + ' :: Checking status code of response...' | |
if addResp.status_code != 200: | |
print utcToETC() + ' ::', addResp.status_code, 'Error \nExiting...' | |
sys.exit(0001) | |
elif addResp.json() == []: | |
print utcToETC() + ' :: Response Empty! - Problem Adding to Cart\nExiting...' | |
sys.exit(0003) | |
else: | |
print utcToETC() + ' :: ' + str(cw) + ' - ' + addResp.json()[0]['name'] + ' - ' + addResp.json()[0][ | |
'size_name'] + ' added to cart!' | |
return addResp | |
# checkout the item added to your cart | |
# Needs variant, sleeptime | |
def checkout(variant, sleepTime): | |
checkoutUrl = "https://www.supremenewyork.com/checkout.json" | |
checkoutHeaders = { | |
'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' | |
} | |
checkoutPayload = { | |
'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' | |
} | |
for i in range(sleepTime): | |
sys.stdout.write("\r" + utcToETC() + ' :: Sleeping for ' + str(sleepTime - i) + ' seconds to avoid ghost checkout...') | |
sys.stdout.flush() | |
time.sleep(1) | |
print utcToETC(), ":: Starting checkout request!" | |
for i in range(5): | |
try: | |
session = requests.Session() | |
checkoutResp = session.post(checkoutUrl, data=checkoutPayload, headers=checkoutHeaders) | |
print utcToETC(), ":: Checkout", checkoutResp.json()['status'].title(), '!' | |
except requests.exceptions.RequestException as e: | |
print e | |
sys.exit(0002) | |
else: | |
print utcToETC(), ":: ERROR ::", checkoutResp.json()['errors'] | |
time.sleep(1) | |
# Main function | |
# hella tuples because of how many return variables there are | |
# At least it's cool, though | |
def main(): | |
utcToETC() | |
sleepTime, poll, keyword, color, size = getInformation() | |
jsonData = getJsonData("http://www.supremenewyork.com/mobile_stock.json") | |
myProduct, ID, jsonUrl = lookupItems(jsonData, keyword, poll) | |
variant, cw, found, ID = lookupSize(myProduct, ID, jsonUrl, color, size) | |
addToCart(variant, cw, ID) | |
checkout(variant, sleepTime) | |
# Run it | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or openssl, either one