-
Notifications
You must be signed in to change notification settings - Fork 11
/
bot.py
68 lines (62 loc) · 2.13 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# - *- coding: utf- 8 - *-
import requests
import json
import browserOps
import threading
from fake_useragent import UserAgent
from concurrent.futures import ThreadPoolExecutor as Pool
proxies = {
'http: '
'https: '
}
sizes = [8.5, 9, 9.5, 10]
thread_count = 8
# :param size spefific size for purchase
def url_gen(model,size):
url = 'https://www.adidas.com/us/yeezy/{}.html?forceSelSize='.format(model) + str(size)
return url
# :param model specific model of sneaker
# :return size_lookup dictionary of sizes/availability
def check_stock(model):
ua = UserAgent()
headers = {'User-Agent':str(ua.msie)}
size_url = 'https://www.adidas.com/api/products/{}/availability?sitePath=us'.format(model)
raw_sizes = (requests.get(size_url,headers=headers)).text
size_data = json.loads(raw_sizes)
# while sneaker availability has not officially released,
# wait until it releases...
if size_data['availability_status'] == 'PREVIEW':
print "Waiting for sizing to be updated..."
check_stock()
list = size_data['variation_list']
size_dict = {}
size_lookup = {}
for i in range(21):
size_dict[i] = {list[i]['size']:list[i]['availability_status']}
for key,value in size_dict.items():
size_lookup.update(value)
return size_lookup
def main():
model = raw_input('Model: ')
size = input('Shoe size: ')
sneaker_bot(model,size)
# Sets up bot environment to automate purchase sneaker if available.
# :param size specific size for purchase
def sneaker_bot(model,size):
sizes = check_stock(model)
url = url_gen(model,size)
if str(size) in sizes:
if str(sizes[str(size)]) == 'IN_STOCK':
print "We're securing you a pair!"
browserOps.process_cart(url)
browserOps.autofill_shipping()
browserOps.autofill_card()
else:
print "Size not available!"
else:
print "We were not able to save you a pair :("
# Allows for multitreading in order to purchase all sizes
# specified in size list
with Pool(thread_count) as executor:
for size in sizes:
executor.submit(sneaker_bot,size)