-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
493 lines (418 loc) · 16.6 KB
/
main.py
File metadata and controls
493 lines (418 loc) · 16.6 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
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
import requests
import cloudscraper
import json
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
def restocks_product_url(SKU):
try:
base_url = 'https://restocks.net/de/shop/search?q='
request_url = base_url + SKU + '&page=1&filters[0][range][price][gte]=1'
r = requests.get(request_url)
json_restocks = json.loads(r.text)
product_url = json_restocks["data"][0]['slug']
print('Scraped Restocks URL: ' + product_url)
return product_url
except:
return("https://restocks.net/de")
def stockx_product_url(SKU):
try:
url = "https://stockx.com/api/browse?_search=" + SKU
headers = {
'accept': 'application/json',
'accept-encoding': 'utf-8',
'accept-language': 'en-DE',
'app-platform': 'Iron',
'referer': 'https://stockx.com/en-DE',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
'x-requested-with': 'XMLHttpRequest'
}
request1 = requests.get(url=url, headers=headers)
product_id = json.loads(request1.text)
product_id_final = product_id['Products'][0]['id']
ID = product_id_final
url_stockX = "https://stockx.com/" + ID
print("Scraped StockX URL: " + url_stockX)
return url_stockX
except:
return("https://stockx.com/")
def sneakit_product_url(SKU):
try:
raw = sneakit_info(SKU)
slug = raw['data'][0]['slug']
p_url = "https://sneakit.com/product/" + slug
print("Scraped Sneakit Product URL:" + p_url)
return p_url
except:
return("https://sneakit.com/")
def hypeboost_product_url(SKU):
try:
url = "https://hypeboost.com/en/search/shop?keyword=" + SKU
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
for a in soup.find_all('a', href=True):
print("Scraped Hypeboost URL:", a['href'])
product_url = a['href']
return product_url
except:
return("https://hypeboost.com/de")
'''
def goat_url(SKU):
try:
url = "https://ac.cnstrc.com/search/" + SKU
querystring = {"c":"ciojs-client-2.29.12","key":"key_XT7bjdbvjgECO5d8","i":"f8b0a5f2-bc6b-4626-b980-74bbc3b45edf","s":"1","num_results_per_page":"25","_dt":"1678011980760"}
payload = ""
headers = {
"authority": "ac.cnstrc.com",
"accept": "*/*",
"accept-language": "en-DE,en;q=0.9",
"origin": "https://www.goat.com",
"sec-ch-ua": "^\^Chromium^^;v=^\^110^^, ^\^Not",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "^\^Windows^^",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}
response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
output = json.loads(response.text)
output_slug = output['response']['results'][0]['data']['slug']
product_url = "https://www.goat.com/sneakers/" + output_slug
print("Scraped GOAT product URL!")
return product_url
except:
return("https://www.goat.com/")
'''
def product_title(SKU):
try:
product_url = restocks_product_url(SKU)
r = requests.get(product_url)
soup = BeautifulSoup(r.content, 'html.parser')
title = soup.find("div", class_ = "product__title")
title2 = title.text
product_title_formated = title2.replace("\n", "")
print('Scraped Title!')
return product_title_formated
except:
return ("Product title not found!")
def restocks_product_img(SKU,restocks_url):
try:
product_url = restocks_url(SKU)
r = requests.get(product_url)
soup = BeautifulSoup(r.content, 'html.parser')
picture = soup.find("div", class_ = "swiper-wrapper")
image = picture.find_all('img')[0].get('src')
print('Scraped Product picture!')
return image
except:
return ("https://www.freecodecamp.org/news/content/images/2021/03/ykhg3yuzq8931--1-.png")
def restocks_stock(SKU):
try:
base_url = 'https://restocks.net/de/shop/search?q='
request_url = base_url + SKU + '&page=1&filters[0][range][price][gte]=1'
r = requests.get(request_url)
json_restocks = json.loads(r.text)
product_url = json_restocks["data"][0]['slug']
print('Scraped Restocks URL: ' + product_url)
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get(product_url)
cookies = driver.find_element(by=By.ID, value='save__first__localization__button')
cookies.click()
time.sleep(2)
driver.execute_script("window.scrollBy(0,500)", "")
size_list = driver.find_element(by=By.CLASS_NAME, value='select__label')
size_list.click()
time.sleep(2)
prices = driver.find_element(by=By.CLASS_NAME, value='select__size__list').text
prices_replace = prices.replace(" ½", "½")
prices_replace2 = prices_replace.replace("Notify me", "OOS!")
prices_replace3 = prices_replace2.replace(" €", "€")
price_list = prices_replace3.split("\n")
price_list = [item for item in price_list if item != 'Noch 1 auf Lager' and item != 'Noch 2 auf Lager']
driver.quit
result = ""
for i in range(len(price_list)):
if i % 2 == 0:
result += price_list[i] + ": "
else:
result += price_list[i]
if i < len(price_list) - 1 and price_list[i+1] != "":
result += "\n"
return result
except:
return ("Product not found!")
def restocks_stock_payout(SKU):
try:
base_url = 'https://restocks.net/de/shop/search?q='
request_url = base_url + SKU + '&page=1&filters[0][range][price][gte]=1'
r = requests.get(request_url)
json_restocks = json.loads(r.text)
product_url = json_restocks["data"][0]['slug']
print('Scraped Restocks URL: ' + product_url)
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get(product_url)
cookies = driver.find_element(by=By.ID, value='save__first__localization__button')
cookies.click()
time.sleep(2)
driver.execute_script("window.scrollBy(0,500)", "")
size_list = driver.find_element(by=By.CLASS_NAME, value='select__label')
size_list.click()
time.sleep(2)
prices = driver.find_element(by=By.CLASS_NAME, value='select__size__list').text
prices_replace = prices.replace(" ½", ".5")
prices_replace2 = prices_replace.replace("Notify me", "OOS")
prices_replace_n1 = prices_replace2.replace("Noch 1 auf Lager", "")
prices_replace_n2 = prices_replace_n1.replace("Noch 2 auf Lager", "")
prices_replace3 = prices_replace_n2.replace(" €", "")
price_list_dirty = prices_replace3.split("\n")
price_list = []
for element in price_list_dirty:
if element != "":
price_list.append(element)
driver.quit
new_list2 = []
for i in range(len(price_list)):
if i % 2 == 0:
size = price_list[i].replace('.5', '½')
new_list2.append(size)
else:
if price_list[i] != 'OOS':
price = float(price_list[i]) * 0.9 - 20
price_formatted = '{:.2f}'.format(price) + '€'
new_list2.append(price_formatted)
else:
new_list2.append(price_list[i])
new_lst3 = []
for item in new_list2:
if item == "OOS":
new_lst3.append("OOS!")
else:
new_lst3.append(item)
result = ""
for i in range(len(new_lst3)):
if i % 2 == 0:
result += new_lst3[i] + ": "
else:
result += new_lst3[i]
if i < len(new_lst3) - 1 and new_lst3[i+1] != "":
result += "\n"
return result
except:
return ("Product not found!")
def hypeboost_stock(SKU):
try:
url = "https://hypeboost.com/en/search/shop?keyword=" + SKU
headers = {
"cookie": "country=eyJpdiI6ImlCRDJaRExPQkZYNTNlMmM0OWFEQVE9PSIsInZhbHVlIjoiTFRaRW01UW5wNUY2RjZnQzViWGlPYWRtYVRmbmxxMXpoRjNzODlZZUdIZmNLWjZSTFp0Q3htbTFuYUF4ZGkwVSIsIm1hYyI6IjQ0MzBlZTdkZmNhYjVhYmJhMDAzNDhlNjQ3MGU5NzQ1YThkOTk0ZDRkNzYxZGQzYzg0ODI0ZWYzZWZhODBlZGYiLCJ0YWciOiIifQ%253D%253D; currency=eyJpdiI6ImFlbkxaNHJyOHdUZlJFRlJ2dGlna0E9PSIsInZhbHVlIjoieEx2OE01VHhzOGZ1eFdsM09IVDFIZmR6R1hieHpDRDZScWoweVhqTDZjUzY2a3FFUmhQZGdPV2piaFN3OTViTCIsIm1hYyI6IjgzMTY0NDExNzljYjM1MzFmZmM5ZTBhOGY0MjU3ZWViMjA2NjBjYmUwMjg0MDFkMmUyYmJiNTVjYTUxZTk5MjMiLCJ0YWciOiIifQ%253D%253D",
"Content-Type": "application/json"
}
response = requests.request("GET", url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
for a in soup.find_all('a', href=True):
print("Product URL:", a['href'])
response_url = requests.get(a['href'])
soup2 = BeautifulSoup(response_url.text, 'html.parser')
sizes = []
for size_elem in soup2.select('.size'):
if 'available' in size_elem['class']:
label = size_elem.select_one('.label').text
price = size_elem.select_one('.price span').text.strip()
sizes.append(f"{label}: {price}")
elif 'sold-out' in size_elem['class']:
label = size_elem.select_one('.label').text
sizes.append(f"{label}: OOS!")
output = "\n".join(element.replace(" €", "€").replace(" ½", "½") for element in sizes)
print("Sizes & Prices Scraped!")
return output
except:
return ("Product not found!")
def hypeboost_prices_payout(SKU):
try:
url = hypeboost_product_url(SKU)
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
sizes = soup.find_all('div', class_='size')
output = ""
for size in sizes:
label = size.find('div', class_='label').text.strip()
if 'data-price' in size.attrs:
price = size['data-price']
price = price.replace('\xa0', '')
price = price.replace(' ', '')
price = price.replace('€', '') + '€'
else:
price = 'OOS!'
output += label.replace(' ', '') + ': ' + price + "\n"
print("Scraped Payout Prices!")
return output
except:
return ("Product not found!")
def sneakit_stock(SKU):
try:
raw = sneakit_info(SKU)
sizes = raw['data'][0]['product_variants_with_shop_price']
result = []
for entry in sizes:
result.append({'size': entry['size'], 'shop_price_in_eur': entry['shop_price_in_eur']})
result = sorted(result, key=lambda x: x['size'])
output_str = ''
for entry in sorted(result, key=lambda x: x['size']):
output_str += f"{entry['size']}: {entry['shop_price_in_eur']}€\n"
print("Scraped Sneakit Prices & Sizes!")
output_str2 = output_str.replace('.5', '½')
return output_str2
except:
return "Product not found!"
def sneakit_url(SKU):
try:
produkt_code = SKU
global url
url = f"https://sneakit.com/search/products/{produkt_code}?query={produkt_code}&page=1"
print("Scraped Sneakit URL!", url)
return url
except:
return("https://sneakit.com/")
def sneakit_info(SKU):
try:
scraper = cloudscraper.create_scraper()
sneakit_url_r = sneakit_url(SKU)
r = scraper.get(sneakit_url_r)
global output
output = json.loads(r.text)
print("Scraped Sneakit info!")
return output
except:
return ("error")
#price after fees
def paypal_fees(price):
try:
price_raw = float(price)
fees1 = price_raw * 0.0249
fees2 = 0.35
all_fees = price_raw - fees1 - fees2
rounden_fees = round(all_fees, 2)
final_price = str(rounden_fees) + "€"
return final_price
except:
return ("something went wrong!")
#only fees
def paypal_fees_2(price):
try:
price_raw = float(price)
fees1 = price_raw * 0.0249
fees2 = 0.35
fees_all_1 = fees1 + fees2
rounded_fees = round(fees_all_1, 2)
fees_all = str(rounded_fees) + "€"
#print(fees_all)
return fees_all
except:
return ("something went wrong!")
#price + fees
def paypal_fees_3(price):
try:
price_raw = float(price)
fees1 = price_raw * 0.0249
fees2 = 0.35
price1 = float(price) + float(fees1) + float(fees2)
rounded_price = round(price1, 2)
rounden_price2 = str(rounded_price) + "€"
return rounden_price2
except:
return ("something went wrong!")
def product_info_url_goat(SKU):
try:
product_id_url = f"https://ac.cnstrc.com/search/{SKU}?c=ciojs-client-2.29.12&key=key_XT7bjdbvjgECO5d8&i=5c1db6a2-7a42-4cbd-9606-96a08face508&s=23&num_results_per_page=25&_dt=1679422941544"
scraper = cloudscraper.create_scraper()
request = scraper.get(product_id_url)
json_product = json.loads(request.text)
ID = json_product['response']['results'][0]['data']['id']
base_url = "https://www.goat.com/web-api/v1/product_variants/buy_bar_data?productTemplateId="
request_url = base_url + ID + "&countryCode=EU"
print("Scraped GOAT URL!")
return request_url
except:
return ("https://www.goat.com/")
def product_sizes_goat(SKU):
try:
request_url = product_info_url_goat(SKU)
scraper = cloudscraper.create_scraper()
request = scraper.get(request_url)
output = json.loads(request.text)
results = []
for entry in output:
if (entry['shoeCondition'] == "new_no_defects") and (entry['boxCondition'] == "good_condition"):
size = entry['sizeOption']['presentation']
try:
price_cents = entry['lowestPriceCents']['amount']
except KeyError:
price_cents = 'OOS!'
results.append((size, price_cents))
results2 = []
for entry in output:
if (entry['shoeCondition'] == "new_no_defects") and (entry['boxCondition'] == "good_condition"):
size = entry['sizeOption']['presentation']
try:
price_cents = entry['lowestPriceCents']['amount'] / 100
price_euro1 = price_cents - 1
price_euro = str(price_euro1) + "€"
except KeyError:
price_euro = 'OOS!'
results2.append((size, price_euro))
prices = [(size, price.replace('.0', '')) for size, price in results2]
output_str = ""
for element in prices:
output_str += f"{element[0]} : {element[1]}\n"
print("Scraped GOAT prices!")
return output_str
except:
return ("Product not found!")
def product_img_goat(SKU):
try:
url = f"https://ac.cnstrc.com/search/{SKU}?c=ciojs-client-2.29.12&key=key_XT7bjdbvjgECO5d8&i=5c1db6a2-7a42-4cbd-9606-96a08face508&s=23&num_results_per_page=25&_dt=1679422941544"
scraper = cloudscraper.create_scraper()
request = scraper.get(url)
json_product = json.loads(request.text)
img = json_product['response']['results'][0]['data']['image_url']
print("Scraped GOAT product picture!")
return img
except:
return ("https://www.freecodecamp.org/news/content/images/2021/03/ykhg3yuzq8931--1-.png")
def product_title_goat(SKU):
try:
url = f"https://ac.cnstrc.com/search/{SKU}?c=ciojs-client-2.29.12&key=key_XT7bjdbvjgECO5d8&i=5c1db6a2-7a42-4cbd-9606-96a08face508&s=23&num_results_per_page=25&_dt=1679422941544"
scraper = cloudscraper.create_scraper()
request = scraper.get(url)
json_product = json.loads(request.text)
title = json_product['response']['results'][0]['value']
print("Scraped GOAT product title!")
return title
except:
return ("Title not found!")
def product_url_goat(SKU):
try:
base_url = "https://www.goat.com/sneakers/"
url = f"https://ac.cnstrc.com/search/{SKU}?c=ciojs-client-2.29.12&key=key_XT7bjdbvjgECO5d8&i=5c1db6a2-7a42-4cbd-9606-96a08face508&s=23&num_results_per_page=25&_dt=1679422941544"
scraper = cloudscraper.create_scraper()
request = scraper.get(url)
json_product = json.loads(request.text)
slug = json_product['response']['results'][0]['data']['slug']
product_url = base_url + slug
print("Scraped GOAT product url: " + product_url)
return product_url
except:
return("https://www.goat.com/")