forked from 13476075014/snkrsbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
172 lines (137 loc) · 6.16 KB
/
Copy pathmain.py
File metadata and controls
172 lines (137 loc) · 6.16 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#coding=utf-8
from loginnk import *
import re
import requests
from WebLoginnk import *
import threading,sqlite3,time
from multiprocessing import Process
from multiprocessing import Queue
def getPostpayLink(productId, shoesLink):
url = "https://api.nike.com/merch/products/v2/" + productId
response = requests.get(url).json()
postpayLink = shoesLink + "?LEStyleColor={styleColor}&LEPaymentType=Alipay".format(
styleColor=response["styleColor"])
return postpayLink
def buySet(shoesUrl):
response = requests.get(shoesUrl).text
launchId = re.findall(r"\"launchViewId\":\"(.*?)\"", response, re.S | re.I)[0]
size = re.findall(r"\"sizes\":(.*?),\"_fetchedAt\"", response, re.S | re.I)[0]
productId = re.findall(r"product\":{\"productId\":\"(.*?)\"", response, re.S | re.I)[0]
shoesLink = re.findall(r"canonical\" href=\"(.*?)\"", response, re.S | re.I)[0]
postpayLink = getPostpayLink(productId, shoesLink)
stock = []
outOfStock = []
j_size = json.loads(size)
for s in j_size:
if j_size[s]["available"]:
stock.append(j_size[s]["localizedSize"])
else:
outOfStock.append(j_size[s]["localizedSize"])
stock.sort()
outOfStock.sort()
if len(outOfStock) > 0:
print(" ".join(outOfStock) + "尺码缺货\n请选择" + " ".join(stock))
else:
print("所有尺码有货\n请选择" + " ".join(stock))
shoesSize = input("-->")
for s in j_size:
if j_size[s]["localizedSize"] == shoesSize:
usShoesSize = s
skuId = j_size[s]["skuId"]
# print("请设置好默认收货地址")
# print("请选择支付方式 1.银联 2.微信 3.支付宝")
# purMethod = input("-->")
# shoesBuyUrl = shoesUrl + "/?productId=" + launchId + "&size=" + usShoesSize
return shoesSize, launchId, skuId, productId, postpayLink
if __name__ == '__main__':
shoesSize, launchId, skuId, productId, postpayLink = buySet(
"https://www.nike.com/cn/launch/t/air-max-270-volt-black-oil-grey/")
threads = int(input("根据参与用户数量自行设置一个购买和监控的线程数:"))
userInfoList = []
def bulkPurchase(orderQueue):
def buy(refreshToken, username, password):
try:
app = BuySnkrs(refreshToken, skuId, launchId, productId, postpayLink)
setShippingOptionsIdResponse = app.setShippingOptionsId()
# print(setShippingOptionsIdResponse)
setCheckoutIdResponse = app.setCheckoutId()
# print(setCheckoutIdResponse)
totalPrice, priceChecksum = app.getPriceChecksum()
# print(totalPrice, priceChecksum)
paymentToken = app.getPaymentToken(totalPrice)
# print(paymentToken)
launchEntrie = app.launchEntrie(paymentToken, priceChecksum)
userInfo = [refreshToken, launchEntrie["id"], username, password]
orderQueue.put(userInfo)
except:
traceback.print_exc()
finally:
td.release()
conn = sqlite3.connect("nike.db")
conn.text_factory = str
c = conn.cursor()
allUser = c.execute("SELECT * from nike").fetchall()
td = threading.BoundedSemaphore(threads)
threadlist = []
for user in allUser:
username = user[2]
password = user[3]
refreshToken = user[1]
#print("%s %s %s",username,password,refreshToken)
td.acquire()
t = threading.Thread(target=buy, args=(refreshToken, username, password))
t.start()
threadlist.append(t)
for x in threadlist:
x.join()
c.close()
def orderStatus(orderQueue):
def checkStatus(u):
try:
token, order, usr, pwd = u
url = "https://unite.nikecloud.com/tokenRefresh?backendEnvironment=identity&locale=zh_CN&mobile=true&native=true&uxId=com.nike.commerce.snkrs.ios&sdkVersion=2.8.4&backendEnvironment=identity&platform=ios&browser=uniteSDK"
data = {"client_id": "G64vA0b95ZruUtGk1K0FkAgaO3Ch30sj", "grant_type": "refresh_token",
"refresh_token": token}
r = requests.post(url, json=data).json()
accessToken = r["access_token"]
headers = {"authorization": "Bearer " + accessToken}
response = requests.get("https://api.nike.com/launch/entries/v2/" + order, headers=headers).json()
print(usr, response)
try:
result = response["result"]
except:
return
if result["status"] == "WINNER":
print("抢购成功, 帐号:%s 密码:%s (自行登陆手机app可查看订单)" % (usr, pwd))
userInfoList.remove(u)
elif result["status"] == "NON_WINNER":
print("%s 抢购失败" % usr)
userInfoList.remove(u)
except:
traceback.print_exc()
finally:
td.release()
while True:
if not orderQueue.empty():
userInfo = orderQueue.get(True)
userInfoList.append(userInfo)
else:
if len(userInfoList) != 0:
td = threading.BoundedSemaphore(threads)
threadlist = []
for u in userInfoList:
td.acquire()
t = threading.Thread(target=checkStatus, args=(u,))
t.start()
threadlist.append(t)
for x in threadlist:
x.join()
else:
time.sleep(2)
orderQueue = Queue()
#buy = Process(target=bulkPurchase, args=(orderQueue,))
#status = Process(target=orderStatus, args=(orderQueue,))
#buy.start()
#status.start()
bulkPurchase(Queue())
orderStatus(Queue())