Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
- import requests
- from bs4 import BeautifulSoup
- import time
- import json
- import redis
- from dhooks import Webhook, Embed
- import random
- def setProductVars(featData, db):
- productList = []
- for style in featData2:
- prodID = product["id"]
- name = product["name"]
- priceDollar = product["price"]
- priceEuro = product["price_euro"]
- stylename = style["name"]
- styleid = style["id"]
- styleidstr = str(styleid)
- image = style["image_url"]
- sizename = ""
- for size in style["sizes"]:
- if (size["stock_level"] == 1):
- checkSizes = True
- sizename = sizename + "\n" + size["name"]
- else:
- checkSizes = False
- print("Product OOS")
- productDict = {"name":name,"id":prodID, "priceD":priceDollar, "category":category, "priceE":priceEuro, "color":stylename, "image":image, "size":sizename, "styleid": styleid}
- if (size["stock_level"] == 1):
- try:
- check = db.__getattribute__(styleidstr+"avail")
- if check == 0:
- sendAlert(productDict, hook)
- print("RESTOCK SENDING ALERT..")
- else:
- db.__setattr__(styleidstr, 1)
- try:
- sizeCheck = db.__getattribute__(styleidstr+"size")
- if sizeCheck != size:
- sendAlert(productDict, hook)
- print("new sizes available")
- except AttributeError: #this means there is no key set with sizes
- db.__setattr__(styleidstr+"size",productDict['size'])
- except AttributeError: #this means the product is new, it hasn't existed in db before.
- sendAlert(productDict, hook)
- print("NEW PRODUCT SENDING ALERT..")
- db.__setattr__(styleidstr+"avail",1) # in stock
- else:
- try:
- check = db.__getattribute__(styleidstr)
- if check == 0:
- continue
- if check == 1:
- print("product went out of stock.")
- except AttributeError:
- db.__setattr__(styleidstr+"avail",0) # OOS
- return productList
- def setDB():
- r = redis.Redis(
- host="localhost",
- port=6379,
- db=0
- )
- return r
- def sendAlert(productDict, hook):
- embed = Embed(
- title = productDict['name'],
- url = "https://www.supremenewyork.com/shop/" + str(productDict['id']),
- description="**Price: **" + "$"+ str(productDict['priceD'] / 100) +" / €"+str(productDict['priceE'] / 100) + " | **www.supremenewyork.com**",
- color=6381785,
- timestamp='now' # sets the timestamp to current time
- )
- RocketNotifylogo = 'https://pbs.twimg.com/profile_images/1137373595481640960/hEQPii0r_400x400.jpg'
- embed.set_footer(text='RocketNotify', icon_url=RocketNotifylogo)
- embed.add_field(name='Color', value=productDict['color'], inline="true")
- embed.add_field(name='Category', value=productDict['category'], inline="true")
- if checkSizes == True:
- embed.add_field(name='Sizes', value=productDict['size'], inline="false")
- embed.set_thumbnail('http:' + productDict['image'])
- response = hook.send(embed=embed, username = "Rocket Notify - Supreme", avatar_url = "https://i.imgur.com/FQFqKia.jpg")
- print("Sending webhook")
- hook = Webhook('https://discordapp.com/api/webhooks/589908516114792458/BUGjfiOJqgEuyFMa0UHdZIeRgmBlORIyjEXr3lctiYL6J8FS4sl3E2KZtz1oFk4x0gn5')
- productList = []
- db = setDB
- def loadProxies():
- with open("C:/Users/test/Desktop/Bots/Monitor/Proxies.txt") as f:
- lines = [line.rstrip('\n') for line in f]
- return lines
- proxies = loadProxies() #load all proxies into a list.
- MAX = len(proxies) -1
- while True:
- supremeEndpoint1 = "http://www.supremenewyork.com/mobile_stock.json"
- supremeEndpoint2 = "https://www.supremenewyork.com/shop/"
- # set the headers like we are a browser,
- headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 'content-type':'application/json'}
- ranNum = random.randint(0,MAX)
- proxy = {"http": proxies[ranNum],
- "https": proxies[ranNum]
- }
- try:
- supremeResponse1 = requests.get(supremeEndpoint1, headers)
- print('Before delay')
- time.sleep(0.5)
- print('After Delay')
- except (KeyboardInterrupt, SystemExit):
- raise
- except:
- proxies.remove(proxy["http"])
- MAX -= 1
- print("bad proxy error")
- continue
- checkSizes = False
- featData = json.loads(supremeResponse1.text)
- allcategories = featData["products_and_categories"]
- for category in allcategories:
- if category != "new":
- print(category)
- for product in allcategories[category]:
- if (product["new_item"] == True):
- try:
- supremeResponse2 = requests.get(supremeEndpoint2 + str(product["id"]) + ".json", headers)
- except (KeyboardInterrupt, SystemExit):
- raise
- except:
- proxies.remove(proxy["http"])
- MAX -= 1
- print("bad proxy error")
- continue
- featData2 = json.loads(supremeResponse2.text)["styles"]
- setProductVars(featData, db)
- #time.sleep(3.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement