-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
325 lines (295 loc) · 15.6 KB
/
main.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
import requests
import json
from discord.ext import commands
import discord
from webserver import keep_alive
from dateutil import parser
import pytz
from os import system
import time
bot = commands.Bot(command_prefix="!", help_command=None)
headers = {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
}
def api_link(styleColor, merchGroup, country):
mx_api = f"https://api.nike.com/deliver/available_gtins/v2/?filter=styleColor%28{styleColor}%29&filter=shipNode%28MX_FAST%29"
api = f"https://api.nike.com/deliver/available_gtins/v2/?filter=styleColor%28{styleColor}%29&filter=merchGroup%28{merchGroup}%29"
if country == "MX" or country == "mx":
return mx_api
else:
return api
def link(styleColor, countryCode, language, mode):
webstoreURL = f"https://api.nike.com/product_feed/threads/v2/?filter=marketplace%28{countryCode}%29&filter=language%28{language}%29&filter=channelId%28d9a5bc42-4b9c-4976-858a-f159cf99c647%29&filter=productInfo.merchProduct.styleColor%28{styleColor}%29"
snkrsURL = f"https://api.nike.com/product_feed/threads/v2/?filter=marketplace%28{countryCode}%29&filter=language%28{language}%29&filter=channelId%28010794e5-35fe-4e32-aaff-cd2c74f89d61%29&filter=productInfo.merchProduct.styleColor%28{styleColor}%29"
if mode == "webstore":
return webstoreURL
else:
return snkrsURL
@bot.command()
async def run(country, styleColor, mode, ctx):
storage = []
api_level = []
backend_level = []
upcomingItem = {}
dates = {}
sizes = []
f = open("country_available.json")
data = json.load(f)
country = country.lower()
for item in data["region"]:
if country == item["country"]:
countryCode = item["country"]
country = countryCode.upper()
language = item["language"]
merchGroup = item["merchGroup"]
storage.append(country)
storage.append(language)
storage.append(merchGroup)
mx_api = f"https://api.nike.com/deliver/available_gtins/v2/?filter=styleColor%28{styleColor}%29&filter=shipNode%28MX_FAST%29"
api = f"https://api.nike.com/deliver/available_gtins/v2/?filter=styleColor%28{styleColor}%29&filter=merchGroup%28{storage[2]}%29"
if country == "MX" or country == "mx":
requests2 = requests.get(mx_api, headers=headers).json()
else:
requests2 = requests.get(api, headers=headers).json()
for stockLevel in requests2["objects"]:
level = {}
level["gtin"] = stockLevel["gtin"]
level["level"] = stockLevel["level"]
api_level.append(level)
snkrsURL = f"https://api.nike.com/product_feed/threads/v2/?filter=marketplace%28{storage[0]}%29&filter=language%28{storage[1]}%29&filter=channelId%28010794e5-35fe-4e32-aaff-cd2c74f89d61%29&filter=productInfo.merchProduct.styleColor%28{styleColor}%29"
stockx = "https://stockx.com/search?s=" + styleColor
goat = "https://www.goat.com/search?query=" + styleColor
request = requests.get(snkrsURL, headers=headers).json()
checking = []
pages = request["pages"]["totalPages"]
checking.append(pages)
if checking[0] == 0:
embed = discord.Embed(title="Item not found!", color=0x00ff00)
await ctx.send(embed=embed)
else:
for product in request["objects"]:
for item in product["productInfo"]:
if item['merchProduct']['styleColor'] == styleColor:
if mode == 'snkrs':
upcomingItem["shoeTitle"] = \
product["publishedContent"]["properties"]["coverCard"]["properties"]["subtitle"]
upcomingItem["shoeNickname"] = \
product["publishedContent"]["properties"]["coverCard"]["properties"]["title"]
upcomingItem["productUrl"] = f"https://www.nike.com/{storage[0].lower()}/launch/t/" + \
product["publishedContent"]["properties"]["seo"]["slug"]
try:
item["launchView"]
except KeyError:
item
else:
upcomingItem["launchMethod"] = item["launchView"]["method"]
upcomingItem["launchStart"] = item["launchView"]["startEntryDate"]
try:
upcomingItem["launchEnd"] = item["launchView"]["stopEntryDate"]
except KeyError:
upcomingItem["launchEnd"] = "Not Found"
elif mode == 'nike':
upcomingItem["shoeTitle"] = product["publishedContent"]["properties"]["title"]
upcomingItem["shoeNickname"] = product["publishedContent"]["properties"]["subtitle"]
upcomingItem["productUrl"] = f"https://www.nike.com/{storage[0].lower()}/t/" + \
product["publishedContent"]["properties"]["seo"][
"slug"] + f"/{styleColor}"
try:
upcomingItem["startDate"] = item["launchView"]["startEntryDate"]
except KeyError:
upcomingItem["startDate"] = item["merchProduct"]["commerceStartDate"]
try:
upcomingItem["publishType"] = item["launchView"]["method"]
except KeyError:
try:
upcomingItem["publishType"] = item["merchProduct"]["publishType"]
except KeyError:
upcomingItem["publishType"] = "UNDEFINED"
upcomingItem["currency"] = item["merchPrice"]["currency"]
upcomingItem["price"] = item["merchPrice"]["fullPrice"]
upcomingItem["colorway"] = item["productContent"]["colorDescription"]
upcomingItem["quantityLimit"] = item["merchProduct"]["quantityLimit"]
upcomingItem["marketplace"] = product["marketplace"]
upcomingItem["status"] = item["merchProduct"]["status"]
upcomingItem["imgUrl"] = item["imageUrls"]["productImageUrl"]
try:
item["skus"]
except KeyError:
item
else:
for shoeSize in item["skus"]:
for cm in shoeSize["countrySpecifications"]:
tempSize = {}
tempSize["gtin"] = shoeSize["gtin"]
if country == "MX":
tempSize["nikeSize"] = shoeSize["nikeSize"] + " / " + cm["localizedSize"] + "CM"
else:
tempSize["nikeSize"] = shoeSize["nikeSize"]
backend_level.append(tempSize)
for item1 in api_level:
for item2 in backend_level:
listing = {}
asdf = []
if item1["gtin"] == item2["gtin"]:
listing["nikeSize"] = item2["nikeSize"]
listing["level"] = item1["level"]
size = listing["nikeSize"]
level = listing["level"]
asdf.append("US")
asdf.append(size)
asdf.append("--**" + level + "**\n")
sizes.append(asdf)
itemName = upcomingItem["shoeTitle"] + " " + upcomingItem["shoeNickname"]
pricing = upcomingItem["currency"] + " " + str(upcomingItem["price"])
latest = []
try:
sizes.sort(key=lambda company: float(company[1]))
for item in sizes:
xxxx = ' '.join(c for c in (item))
latest.append(xxxx)
except ValueError:
for item in sizes:
xxxx = ' '.join(c for c in (item))
latest.append(xxxx)
usethis = ' '.join(a for a in latest)
timezone = pytz.timezone('Asia/Kuala_Lumpur')
if mode == 'snkrs':
try:
date = parser.parse(upcomingItem["launchStart"]).astimezone(tz=timezone)
dates['date1'] = (date.strftime('%Y-%m-%d %I:%M:%S%p'))
except:
dates['date1'] = "Not Found"
try:
date = parser.parse(upcomingItem["launchEnd"]).astimezone(tz=timezone)
dates['date2'] = (date.strftime('%Y-%m-%d %I:%M:%S%p'))
except:
dates['date2'] = "Not Found"
pass
elif mode == 'nike':
date = parser.parse(upcomingItem['startDate']).astimezone(tz=timezone)
dates['date1'] = (date.strftime('%Y-%m-%d %I:%M:%S%p'))
links = f"[StockX]({stockx})"
links2 = f"[Goat]({goat})"
embed = discord.Embed(title=itemName, url=upcomingItem['productUrl'], color=0x00ff00)
embed.set_thumbnail(url=upcomingItem["imgUrl"])
embed.add_field(name="Status", value=upcomingItem["status"])
if mode == 'snkrs':
embed.add_field(name="Launch Method", value=upcomingItem["launchMethod"])
elif mode == 'nike':
embed.add_field(name="Method", value=upcomingItem["publishType"], inline=True)
embed.add_field(name="Cart Limit", value=upcomingItem["quantityLimit"], inline=True)
embed.add_field(name="Style Color", value=styleColor, inline=True)
embed.add_field(name="Country", value=upcomingItem["marketplace"], inline=True)
embed.add_field(name="Price", value=pricing, inline=True)
embed.add_field(name="Colorway", value=upcomingItem["colorway"], inline=True)
if mode == 'snkrs':
embed.add_field(name="LaunchStart", value=dates['date1'], inline=False)
embed.add_field(name="LaunchEnd", value=dates['date2'], inline=False)
elif mode == 'nike':
embed.add_field(name="Start Date", value=dates['date1'], inline=False)
if usethis is not None:
embed.add_field(name="Size Available", value=usethis)
else:
embed.add_field(name="Size Available", value="No Size Yet")
embed.add_field(name="Links", value=links + " | " + links2, inline=False)
await ctx.send(embed=embed)
print(upcomingItem)
@bot.command(pass_context=True)
async def snkrs(ctx, styleColor, country):
mode = 'snkrs'
await run(country, styleColor, mode, ctx)
@bot.command(pass_context=True)
async def nike(ctx, styleColor, country):
mode = 'nike'
await run(country, styleColor, mode, ctx)
@bot.command()
async def launch(ctx, country):
results = []
with open("country_available.json") as f:
jdata = json.load(f)
countryList = []
for item in jdata['region']:
temp = {}
temp['country'] = item['country'].upper()
temp['language'] = item['language']
countryList.append(temp)
newCountry = country.upper()
tempLanguage = []
for item in countryList:
item['country'].upper()
if item['country'] == newCountry:
tempLanguage.append(item['language'])
url = f"https://api.nike.com/product_feed/threads/v2/?filter=marketplace%28{newCountry}%29&filter=language%28{tempLanguage[0]}%29&filter=employeePrice%28true%29&filter=upcoming%28true%29&filter=channelId%28010794e5-35fe-4e32-aaff-cd2c74f89d61%29&sort=effectiveStartSellDateAsc&fields=active,id,lastFetchTime,productInfo,publishedContent.nodes,publishedContent.subType,publishedContent.properties.coverCard,publishedContent.properties.productCard,publishedContent.properties.products,publishedContent.properties.publish.collections,publishedContent.properties.relatedThreads,publishedContent.properties.seo,publishedContent.properties.threadType,publishedContent.properties.custom,publishedContent.properties.title"
print(url)
timezone = pytz.timezone('Asia/Kuala_Lumpur')
launches = requests.get(url, headers=headers)
for product in launches.json()["objects"]:
for item in product["productInfo"]:
upcomingItem = {}
upcomingItem["shoeTitle"] = product["publishedContent"]["properties"]["coverCard"]["properties"]["subtitle"]
upcomingItem["shoeNickname"] = product["publishedContent"]["properties"]["coverCard"]["properties"]["title"]
upcomingItem["gender"] = item["merchProduct"]["genders"]
upcomingItem["price"] = str(item["merchPrice"]["currency"] + " " + str(item["merchPrice"]["fullPrice"]))
upcomingItem["productUrl"] = f"https://www.nike.com/{newCountry.lower()}/launch/t/" + \
product["publishedContent"]["properties"]["seo"]["slug"]
upcomingItem["colorway"] = item["productContent"]["colorDescription"]
upcomingItem["styleColor"] = item["merchProduct"]["styleColor"]
upcomingItem["quantityLimit"] = item["merchProduct"]["quantityLimit"]
try:
item["launchView"]
except KeyError:
item
else:
try:
upcomingItem["launchMethod"] = item["launchView"]["method"]
except KeyError:
upcomingItem["launchMethod"] = "Not Found"
try:
date = parser.parse(item["launchView"]["startEntryDate"]).astimezone(tz=timezone)
date1 = (date.strftime('%Y-%m-%d %I:%M:%S%p'))
upcomingItem["launchStart"] = date1
except KeyError:
upcomingItem["launchStart"] = "Not Found"
try:
date = parser.parse(item["launchView"]["stopEntryDate"]).astimezone(tz=timezone)
date2 = (date.strftime('%Y-%m-%d %I:%M:%S%p'))
upcomingItem["launchEnd"] = date2
except KeyError:
upcomingItem["launchEnd"] = "Not Found"
upcomingItem["imgUrl"] = item["imageUrls"]["productImageUrl"]
results.append(upcomingItem)
for item in results:
stockx = "https://stockx.com/search?s=" + item['styleColor']
goat = "https://www.goat.com/search?query=" + item['styleColor']
links = f"[StockX]({stockx})"
links2 = f"[Goat]({goat})"
try:
embed = discord.Embed(title=item['shoeTitle'] + " " + item['shoeNickname'], url=item['productUrl'],
color=0x00ff00)
embed.set_thumbnail(url=item["imgUrl"])
embed.add_field(name="Launch Method", value=item["launchMethod"])
embed.add_field(name="Cart Limit", value=item["quantityLimit"])
embed.add_field(name="Style Color", value=item["styleColor"])
embed.add_field(name="Price", value=item["price"], inline=False)
embed.add_field(name="Colorway", value=item["colorway"], inline=False)
embed.add_field(name="LaunchStart", value=item['launchStart'], inline=False)
embed.add_field(name="LaunchEnd", value=item['launchEnd'], inline=False)
embed.add_field(name="Links", value=links + " | " + links2, inline=False)
await ctx.send(embed=embed)
except KeyError:
print(item)
time.sleep(1)
keep_alive()
token = 'YOUR DISCORD TOKEN'
def play():
try:
bot.run(token)
# except discord.errors.HTTPException:
except:
system("python restarter.py")
system('kill 1')
while True:
play()
time.sleep(1800)
print("Done")