-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_1201.py
441 lines (415 loc) · 11.3 KB
/
test_1201.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/env python3
import selenium
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver import ActionChains
import time
from selenium.common.exceptions import NoSuchElementException as NoSuchElementException
from selenium.common.exceptions import ElementNotInteractableException as ElementNotInteractableException
import threading
import sys
# define driver
#chromedriver = '/usr/local/bin/chromedriver'
chromedriver = '/opt/homebrew/bin/chromedriver'
driver = webdriver.Chrome(chromedriver)
#driver = webdriver.Chrome(ChromeDriverManager().install())
cart_url = "https://store.isseymiyake.com/p/cart?type=purchase"
sleep_sec = 1
options = [
# first
#編號1
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(0, 0): 3, # No. 12 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '1-1'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(0, 0): 3, # No. 12 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '1-2'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(0, 0): 3, # No. 12 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '1-3'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(0, 0): 3, # No. 12 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '1-4'
},
#編號2
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(1, 0): 6, # No. 15 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '1-5'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(1, 0): 6, # No. 15 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '1-6'
},
# second
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(1, 0): 6, # No. 15 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '2-1'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JF283',
'item_to_buy': {
(1, 0): 6, # No. 15 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '2-2'
},
#編號3
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '2-3'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '2-4'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '2-5'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '2-6'
},
# third
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '3-1'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '3-2'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '3-3'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(0, 0): 5, # NO 12色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '3-4'
},
#編號4
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '3-5'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '3-6'
},
# fourth
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '4-1'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '4-2'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '4-3'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '4-4'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '4-5'
},
{
'url': 'https://store.isseymiyake.com/c/pl_all_all/PP13JK281',
'item_to_buy': {
(1, 0): 5, # NO 15色 SIZE 3
},
'account':'[email protected]',
'password':'777seven',
'description': '4-6'
},
]
#login
def login(account, password):
start_time = time.time()
print("try to login!")
driver.get('https://store.isseymiyake.com/my/top')
driver.find_element_by_name('mailAddress').send_keys(account)
driver.find_element_by_name('password').send_keys(password)
print("click login button!")
try:
loginButton = driver.find_elements_by_class_name("fs-c-button--login")
loginButton[0].click()
except ElementNotInteractableException:
pass
print('---%s seconds ---' % (time.time() - start_time))
def check_items_quantity(item_to_buy, url):
start_time = time.time()
driver.get(url)
print("item name you're checking is: ", driver.title.split('|')[0])
print("product names are: ")
item_cnt = 0
try:
html_list = driver.find_elements_by_class_name("fs-c-variationList__item__cart")
for i in range(len(html_list)):
items = html_list[i].find_elements_by_tag_name("li")
for j in range(len(items)):
if (i,j) in item_to_buy:
if(item_to_buy[(i,j)] > 0):
print((i,j))
print("quantity to buy: ", item_to_buy[(i,j)])
button = items[j].find_elements_by_tag_name("button")
#if(button[1].text != "入荷お知らせメール"):
for k in range(len(button)):
if button[k].text == 'カートに入れる':
try:
print('button text: ', button[k].text)
print('click button!')
button[k].click()
item_cnt += 1
item_to_buy[(i,j)] -= 1
except selenium.common.exceptions.ElementNotInteractableException:
print('element not exist!')
# productButton = driver.find_elements_by_class_name("fs-c-button--addToCart--variation")
print("There are " + str(item_cnt) + " items you can buy!")
print('---%s seconds ---' % (time.time() - start_time))
return item_cnt
except NoSuchElementException:
print("No product list!")
print('---%s seconds ---' % (time.time() - start_time))
return 0
def finish_buy(confirm):
start_time = time.time()
finish_flag = False
print("go to cart!")
cnt = 0
while not finish_flag:
driver.get(cart_url)
print("purchase!")
purchaseButton = driver.find_elements_by_class_name("fs-c-button--purchaseHere")
print(len(purchaseButton))
try:
purchaseButton[0].click()
print('finish!')
finish_flag = True
except IndexError:
print('no purchase button! close toast!')
print(cnt)
# return False
if cnt > 5:
return False
closeButton = driver.find_elements_by_class_name('iziToast-close')
try:
cnt += 1
for i in closeButton:
i.click()
except selenium.common.exceptions.StaleElementReferenceException:
print('stale element!')
break
time.sleep(1)
i = 10
while i > 0:
i = i - 1
try:
Cash_on_delivery_button = driver.find_element_by_xpath(("//label[@for='fs_input_payment_cashOnDelivery']"));
print(Cash_on_delivery_button)
Cash_on_delivery_button.click()
break
except selenium.common.exceptions.NoSuchElementException:
print("no cash on delivery button!")
print('confirm : ', confirm)
if confirm:
for i in range(10):
try:
print('confirm!')
confirmButton = driver.find_elements_by_class_name("fs-c-button--confirmOrder")
time.sleep(1)
print(confirmButton[0].text)
confirmButton[0].click()
time.sleep(2)
return True
except selenium.common.exceptions.StaleElementReferenceException:
print('stale element! try again!')
print('---%s seconds ---' % (time.time() - start_time))
return False
def clear_cart():
start_time = time.time()
print("go to cart!")
driver.get(cart_url)
print("clear cart start!")
clear_flag = False
while not clear_flag:
clearButton = driver.find_elements_by_class_name("fs-c-button--cancel--cart")
if len(clearButton) == 0:
print("clear Done!")
return True
try:
clearButton[0].click()
print("cleared one product!")
time.sleep(1)
except selenium.common.exceptions.StaleElementReferenceException:
print("element missing!")
except IndexError:
print("no clear Button! ")
clear_flag = True
print('---%s seconds ---' % (time.time() - start_time))
def main(idx=0, restart=False):
driver.maximize_window()
url = options[idx]['url']
item_to_buy = options[idx]['item_to_buy']
account = options[idx]['account']
password = options[idx]['password']
if not restart:
login(account=account, password=password)
clear_cart()
item_need_to_buy_count = sum(item_to_buy.values())
while item_need_to_buy_count > 0:
item_need_to_buy_count = sum(item_to_buy.values())
print("item need to buy count: ", item_need_to_buy_count)
print("item_to_buy: ", item_to_buy)
item_quantity = check_items_quantity(item_to_buy, url)
print("quantity: ", item_quantity)
while item_quantity == 0:
item_need_to_buy_count = sum(item_to_buy.values())
print("No product to buy! sleep " + str(sleep_sec) + " secs")
time.sleep(sleep_sec)
driver.refresh()
item_quantity = check_items_quantity(item_to_buy, url)
print("current quantity: ", item_quantity)
if item_need_to_buy_count == 0:
print('bye!')
driver.quit()
exit(-1)
if item_quantity:
print ('real buy: ', sys.argv[2])
if not finish_buy(int(sys.argv[2])):
# time.sleep(1)
clear_cart()
# driver.quit()
if __name__ == '__main__':
if (len(sys.argv) < 3):
print ('wrong number of argv!')
driver.quit()
exit(-1)
idx = int(sys.argv[1])
print('idx is: ', idx)
try:
main(idx=idx, restart=False)
except selenium.common.exceptions.NoSuchWindowException:
print('bye!')
driver.quit()
exit(-1)
# while True:
# pass