Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. #! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
  2.  
  3. import requests
  4. from bs4 import BeautifulSoup
  5. import time
  6. import json
  7. import redis
  8. from dhooks import Webhook, Embed
  9. import random
  10.  
  11. def setProductVars(featData, db):
  12. productList = []
  13. for style in featData2:
  14. prodID = product["id"]
  15. name = product["name"]
  16. priceDollar = product["price"]
  17. priceEuro = product["price_euro"]
  18. stylename = style["name"]
  19. styleid = style["id"]
  20. styleidstr = str(styleid)
  21. image = style["image_url"]
  22. sizename = ""
  23. for size in style["sizes"]:
  24. if (size["stock_level"] == 1):
  25. checkSizes = True
  26. sizename = sizename + "\n" + size["name"]
  27. else:
  28. checkSizes = False
  29. print("Product OOS")
  30. productDict = {"name":name,"id":prodID, "priceD":priceDollar, "category":category, "priceE":priceEuro, "color":stylename, "image":image, "size":sizename, "styleid": styleid}
  31. if (size["stock_level"] == 1):
  32. try:
  33. check = db.__getattribute__(styleidstr+"avail")
  34. if check == 0:
  35. sendAlert(productDict, hook)
  36. print("RESTOCK SENDING ALERT..")
  37. else:
  38. db.__setattr__(styleidstr, 1)
  39. try:
  40. sizeCheck = db.__getattribute__(styleidstr+"size")
  41. if sizeCheck != size:
  42. sendAlert(productDict, hook)
  43. print("new sizes available")
  44. except AttributeError: #this means there is no key set with sizes
  45. db.__setattr__(styleidstr+"size",productDict['size'])
  46. except AttributeError: #this means the product is new, it hasn't existed in db before.
  47. sendAlert(productDict, hook)
  48. print("NEW PRODUCT SENDING ALERT..")
  49. db.__setattr__(styleidstr+"avail",1) # in stock
  50. else:
  51. try:
  52. check = db.__getattribute__(styleidstr)
  53. if check == 0:
  54. continue
  55. if check == 1:
  56. print("product went out of stock.")
  57. except AttributeError:
  58. db.__setattr__(styleidstr+"avail",0) # OOS
  59. return productList
  60.  
  61. def setDB():
  62. r = redis.Redis(
  63. host="localhost",
  64. port=6379,
  65. db=0
  66. )
  67. return r
  68.  
  69. def sendAlert(productDict, hook):
  70. embed = Embed(
  71. title = productDict['name'],
  72. url = "https://www.supremenewyork.com/shop/" + str(productDict['id']),
  73. description="**Price: **" + "$"+ str(productDict['priceD'] / 100) +" / €"+str(productDict['priceE'] / 100) + " | **www.supremenewyork.com**",
  74. color=6381785,
  75. timestamp='now' # sets the timestamp to current time
  76. )
  77.  
  78. RocketNotifylogo = 'https://pbs.twimg.com/profile_images/1137373595481640960/hEQPii0r_400x400.jpg'
  79.  
  80. embed.set_footer(text='RocketNotify', icon_url=RocketNotifylogo)
  81. embed.add_field(name='Color', value=productDict['color'], inline="true")
  82. embed.add_field(name='Category', value=productDict['category'], inline="true")
  83. if checkSizes == True:
  84. embed.add_field(name='Sizes', value=productDict['size'], inline="false")
  85. embed.set_thumbnail('http:' + productDict['image'])
  86.  
  87. response = hook.send(embed=embed, username = "Rocket Notify - Supreme", avatar_url = "https://i.imgur.com/FQFqKia.jpg")
  88. print("Sending webhook")
  89.  
  90. hook = Webhook('https://discordapp.com/api/webhooks/589908516114792458/BUGjfiOJqgEuyFMa0UHdZIeRgmBlORIyjEXr3lctiYL6J8FS4sl3E2KZtz1oFk4x0gn5')
  91. productList = []
  92. db = setDB
  93. def loadProxies():
  94. with open("C:/Users/test/Desktop/Bots/Monitor/Proxies.txt") as f:
  95. lines = [line.rstrip('\n') for line in f]
  96. return lines
  97. proxies = loadProxies() #load all proxies into a list.
  98. MAX = len(proxies) -1
  99.  
  100. while True:
  101. supremeEndpoint1 = "http://www.supremenewyork.com/mobile_stock.json"
  102. supremeEndpoint2 = "https://www.supremenewyork.com/shop/"
  103. # set the headers like we are a browser,
  104. 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'}
  105. ranNum = random.randint(0,MAX)
  106. proxy = {"http": proxies[ranNum],
  107. "https": proxies[ranNum]
  108. }
  109. try:
  110. supremeResponse1 = requests.get(supremeEndpoint1, headers)
  111. print('Before delay')
  112. time.sleep(0.5)
  113. print('After Delay')
  114. except (KeyboardInterrupt, SystemExit):
  115. raise
  116. except:
  117. proxies.remove(proxy["http"])
  118. MAX -= 1
  119. print("bad proxy error")
  120. continue
  121.  
  122. checkSizes = False
  123. featData = json.loads(supremeResponse1.text)
  124. allcategories = featData["products_and_categories"]
  125. for category in allcategories:
  126. if category != "new":
  127. print(category)
  128. for product in allcategories[category]:
  129. if (product["new_item"] == True):
  130. try:
  131. supremeResponse2 = requests.get(supremeEndpoint2 + str(product["id"]) + ".json", headers)
  132. except (KeyboardInterrupt, SystemExit):
  133. raise
  134. except:
  135. proxies.remove(proxy["http"])
  136. MAX -= 1
  137. print("bad proxy error")
  138. continue
  139. featData2 = json.loads(supremeResponse2.text)["styles"]
  140. setProductVars(featData, db)
  141. #time.sleep(3.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement