-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmonitor.py
262 lines (214 loc) · 8.71 KB
/
monitor.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
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
import concurrent.futures
import time
import json
import tweepy
from time import gmtime, strftime
from random import randint
from datetime import datetime
from termcolor import cprint
from tokens import *
import sys
import random
from slackclient import SlackClient
# Get this from masterStock.py
IDs = {'170462':'Denim Logo Chore Coat','170471':'Supreme/LACOSTE Track Jacket','170474':'Supreme/LACOSTE Harrington Jacket','170464':'Polka Dot S/S Shirt','170463':'Curve Logo Tee','170469':'Supreme/LACOSTE L/S Jersey Polo','170473':'Supreme/LACOSTE Tennis Sweater','170465':'666 Zip Up Sweat','170466':'Sequin Logo Hooded Sweatshirt','170468':'Supreme/LACOSTE Pique Crewneck','170472':'Supreme/LACOSTE Track Pant','170470':'Supreme/LACOSTE Pique Short','170460':'Leather Camp Cap','170461':'Skew Nylon 5-Panel','170467':'Supreme/LACOSTE Pique Camp Cap','170459':'Studded Belt'}
IDs = {'170515':'Supreme®/The North Face® Trans Antarctica Expedition Pullover','170516':'Supreme®/The North Face® Trans Antarctica Expedition Fleece Jacket','170517':'Supreme®/The North Face® Trans Antarctica Expedition Pant','170514':'Supreme®/The North Face® Trans Antarctica Expedition Headband','170513':'Supreme®/The North Face® Trans Antarctica Expedition Big Haul Backpack'}
# Get this from proxies.txt
proxyList = [""]
sizeKey = ['OS','SMALL','MEDIUM','LARGE','XLARGE','S/M','L/XL','30','32','34','36',"None"]
stock = {}
def slackMsg(item,color,link, size):
# line 101
if slack_token == "":
return
sc = SlackClient(slack_token)
text = item+"\n"
text += color+'\n'
text += size.title()+'\n'
text += link+'\n'
text += "Restock!"+'\n'
text += str(datetime.utcnow().strftime('%H:%M:%S.%f')[:-3])
sc.api_call(
"chat.postMessage",
channel="#test",
text=text
)
def sendTweet(item,color,link, size):
# line 102
auth = tweepy.OAuthHandler(C_KEY, C_SECRET)
auth.set_access_token(A_TOKEN, A_TOKEN_SECRET)
api = tweepy.API(auth)
tweet = item+"\n"
tweet += color+'\n'
tweet += size.title()+'\n'
tweet += link+'\n'
tweet += "Restock!"+'\n'
tweet += str(datetime.utcnow().strftime('%H:%M:%S.%f')[:-3])
try:
api.update_status(tweet)
print(tweet)
except:
print("Error sending tweet!")
def getIp(proxy):
ip = proxy
global proxies
proxies = {
'http': ip,
'https': ip
}
def compareStock():
global IDs
global stock
global sizeKey
with open("stock.txt", 'r') as outfile:
oldStock = json.load(outfile)
# For testing:
# stock['170423']['Peach'][1] = 1
# stock['170427']['Peach']['sizes']['LARGE'] = 0
# stock['170462']['Red']['sizes']['MEDIUM'] = 1
# stock['170467']["Light Pink"]['sizes']["OS"] = 1
# print(stock['170467']["Kelly Green"]['sizes'])
# etc...
change = 0
for ID in IDs.keys():
try:
for color in stock[ID]:
for size in stock[ID][color]['sizes']:
if (stock[ID][color]['sizes'][size] == 1) and (oldStock[ID][color]['sizes'][size] == 0):
item = IDs[ID]
itemColor = stock[ID][color]['id']
link = "http://www.supremenewyork.com/shop/"+"supszn/"+str(ID)+"/"+str(itemColor)
itemSize = size
sendTweet(item,color,link, itemSize)
slackMsg(item,color,link, itemSize)
with open("stock.txt", 'w') as outfile:
json.dump(stock, outfile, indent=4, sort_keys=True)
elif (stock[ID][color]['sizes'][size] == 0) and (oldStock[ID][color]['sizes'][size] == 1):
stock[ID][color]['sizes'][size] = 2
with open("stock.txt", 'w') as outfile:
json.dump(stock, outfile, indent=4, sort_keys=True)
if (oldStock[ID][color]['sizes'][size] > 1):
stock[ID][color]['sizes'][size] = oldStock[ID][color]['sizes'][size] + 1
cprint(ID+" - OOS! ++ "+str(stock[ID][color]['sizes'][size]),"yellow")
with open("stock.txt", 'w') as outfile:
json.dump(stock, outfile, indent=4, sort_keys=True)
if (oldStock[ID][color]['sizes'][size] == 300):
print("OOS! MAX ")
stock[ID][color]['sizes'][size] = 0
cprint(IDs[ID],"red")
cprint("OOS","red")
change = 1
except:
print(ID)
print(oldStock[ID][color]['sizes'])
cprint("Invalid ID","red")
if change == 1:
with open("stock.txt", 'w') as outfile:
json.dump(stock, outfile, indent=4, sort_keys=True)
if change == 0:
cprint("No changes!","green",attrs=['bold'])
def restockCheck(sku, extra):
global proxyList
global stock
global sizeKey
urlJson = "http://www.supremenewyork.com/shop/" + str(sku) +".json"
user = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"}
success = False
count = 0
while not success:
ip = proxyList[count]
if count == 0:
ip = proxyList[random.randint(0,(len(proxyList) - 1))]
proxies = {
'http': ip,
'https': ip
}
try:
cprint("Loading proxy: {}".format(ip),"blue")
r2 = requests.get(urlJson, headers=user, proxies=proxies, timeout=2)
newStock = json.loads(r2.text)
success = True
break # just incase lol
except:
cprint("Banned ::: "+ip,"red")
count += 1
if count == (len(proxyList) - 1):
exit()
colorDict = {}
for color in newStock['styles']:
url = "http://www.supremenewyork.com/shop/" "sup/"+ str(sku) + "/" + str(color['id'])
r = requests.get(url, headers=user, proxies=proxies, timeout=2)
data = r.text
soup = BeautifulSoup(data,"html.parser")
sizeStock = {}
sizeStock["id"] = color['id']
stockDict = {}
status = str(soup.find(id="add-remove-buttons"))
if "add to basket" in status:
# Get sizes
sizes = soup.find(id="size")
if sizes.find('option') == None:
# print("OS : "+sizes.get('value'))
stockDict['OS'] = 1
for size in sizeKey:
if size not in stockDict.keys():
stockDict[size] = 0
else:
for size in sizes.find_all('option'):
# print(size.text + " : " +size.get('value'))
stockDict[str(size.text).upper()] = 1
for size in sizeKey:
if size not in stockDict.keys():
stockDict[size] = 0
elif "sold out" in status:
stockDict['None'] = 0
for size in sizeKey:
# print(size.text + " : " +size.get('value'))
stockDict[size] = 0
sizeStock['sizes'] = stockDict
colorDict[color['name']] = sizeStock
# time.sleep(.15) # to not get banned
stock[sku] = colorDict
def multiCheck(items):
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
for item in items:
executor.submit(restockCheck, item, 60)
def loadProxies():
proxyList = []
with open("proxies.txt", 'r') as outfile:
proxyList = json.load(outfile)
return proxyList
def main(argv):
global IDs
global stock
if len(sys.argv) > 1:
cprint("First run, saving stock.txt","green")
for ID in IDs.keys():
restockCheck(ID, 1)
time.sleep(.5)
if stock:
with open("stock.txt", 'w') as outfile:
json.dump(stock, outfile, indent=4, sort_keys=True)
cprint("stock.txt saved!","green")
exit()
start_time = time.time()
cprint(str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]), "magenta")
try:
# If you don't want threading:
# for ID in IDs.keys():
# print("Checking: {}".format(ID))
# restockCheck(ID, 1)
# time.sleep(.5)
# Use threading:
multiCheck(list(IDs.keys()))
# print(stock)
if stock:
compareStock()
except:
cprint("ERROR","red", attrs=['bold'])
cprint(str(time.time() - start_time)+" seconds", "magenta", attrs=['bold'])
if __name__ == '__main__':
main(sys.argv)