Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup as soup
  3. import time
  4. import json
  5. import datetime
  6. from random import randint
  7.  
  8. #Set the refresh rate in seconds
  9. interval = 60
  10. #Choose either UK, US or CA
  11. region = "UK"
  12. #Enter your discord webhook here
  13. webhook = "https://discordapp.com/api/webhooks/506155869826711552/ZVTUSvrwsg1l1-qwUDA8iqKlDZBHtuI6YJBhtoxK3Y4_ZCbcxckYws0MI3eh6Tlop9vv"
  14. #If you want to use proxies, set useproxies to True and enter your proxies on individual lines in a file in the same relative directory called proxies.txt
  15. useproxies = False
  16.  
  17. if region.lower() == "uk":
  18. map = "http://www.adidas.co.uk/static/on/demandware.static/-/Sites-CustomerFileStore/default/adidas-GB/en_GB/sitemaps/product/adidas-GB-en-gb-product.xml"
  19. suggestionsbase = "https://www.adidas.co.uk/api/suggestions/"
  20. if region.lower() == "us":
  21. map = "https://www.adidas.com/static/on/demandware.static/-/Sites-CustomerFileStore/default/adidas-US/en_US/sitemaps/product/adidas-US-en-us-product.xml"
  22. suggestionsbase = "https://www.adidas.com/api/suggestions/"
  23. if region.lower() == "ca":
  24. map = "http://www.adidas.ca/static/on/demandware.static/-/Sites-CustomerFileStore/default/adidas-CA/en_CA/sitemaps/product/adidas-CA-en-ca-product.xml"
  25. suggestionsbase = "https://www.adidas.ca/api/suggestions/"
  26.  
  27. headers = {
  28. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  29. 'Accept-Encoding': 'gzip, deflate',
  30. 'Accept-Language': 'en-US,en;q=0.9',
  31. 'Connection': 'keep-alive',
  32. 'Upgrade-Insecure-Requests': '1',
  33. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'}
  34.  
  35. def proxyforreq(proxy):
  36.  
  37. try:
  38. proxy.split(":")[2]
  39. ip = proxy.split(":")[0]
  40. port = proxy.split(":")[1]
  41. userpassproxy = '%s:%s' % (ip, port)
  42. proxyuser = proxy.split(":")[2].rstrip()
  43. proxypass = proxy.split(":")[3].rstrip()
  44. proxies = {'http': 'http://%s:%s@%s' % (proxyuser, proxypass, userpassproxy),
  45. 'https': 'http://%s:%s@%s' % (proxyuser, proxypass, userpassproxy)}
  46.  
  47. except:
  48. proxies = {'http': 'http://%s' % proxy, 'https': 'http://%s' % proxy}
  49.  
  50. return proxies
  51.  
  52.  
  53.  
  54. def gettitle(url, region):
  55. if region.lower() == "uk":
  56. base = url.split("/")[3]
  57. if region.lower() == "us" or region.lower() == "ca":
  58. base = url.split("/")[4]
  59. words = base.split("-")
  60. baretitle = ""
  61. for word in words:
  62. word = word[0].capitalize() + word[1:]
  63. baretitle = baretitle + " %s"%word
  64. title = baretitle[1:]
  65. return title
  66.  
  67.  
  68. def getdata(pid,suggestionsbase,useproxies,proxies):
  69. suggestionspage = suggestionsbase + pid
  70. if useproxies == False:
  71. sug = requests.get(suggestionspage, headers)
  72. else:
  73. sug = requests.get(suggestionspage, proxies=proxies, headers=headers)
  74. sugtext = json.loads(sug.text)
  75. prod = sugtext['products']
  76. prods = prod[0]
  77. price = prods['standardPrice']
  78. price = price.replace(" ", "")
  79. url = prods['image']
  80. return price, url
  81.  
  82.  
  83. def discordpost(title,data,url,webhook,useproxies,proxies):
  84. footer1 = {
  85. "icon_url": "https://pp.userapi.com/c852020/v852020933/82225/2r1UlMkpdnY.jpg",
  86. "text": "Powered by Project SNKRFY | @ProjectSNKRFY"
  87. ""}
  88. thumbnail1 = {
  89. "url": data[1]}
  90. fields1 = [
  91. {
  92. "name": "Price:",
  93. "value": data[0],
  94. "inline": "true"
  95. },
  96. {
  97. "name": "Region:",
  98. "value": region.upper(),
  99. "inline": "false"
  100. },
  101. ]
  102.  
  103. embed = {
  104. "title": title,
  105. "url": url,
  106. "color": 5305409,
  107. "timestamp": str(datetime.datetime.now()),
  108. "footer": footer1,
  109. "thumbnail": thumbnail1,
  110. "fields": fields1
  111. }
  112.  
  113. embed = [embed]
  114. discordjson = {"embeds": embed, "username": "New Adi Item"}
  115. if useproxies == False:
  116. requests.post(webhook, json=discordjson)
  117. else:
  118. requests.post(webhook, proxies=proxies, json=discordjson)
  119.  
  120.  
  121. links = []
  122.  
  123. if useproxies == True:
  124. rawproxies = open('proxies.txt','r').read().splitlines()
  125. else:
  126. rawproxies = ""
  127.  
  128. def loop(index,links,map,useproxies,rawproxies,region):
  129. foundnewlink = False
  130. if useproxies == False:
  131. html = requests.get(map, headers)
  132. else:
  133. if len(rawproxies) == 0:
  134. print("Enter some proxies to use proxies")
  135. if len(rawproxies) == 1:
  136. num = 0
  137. if len(rawproxies) > 1:
  138. num = randint(0, len(rawproxies))
  139.  
  140. proxies = proxyforreq(rawproxies[num])
  141. html = requests.get(map, proxies=proxies, headers=headers)
  142. pagesoup = soup(html.text, "html.parser")
  143. for item in pagesoup.find_all('loc'):
  144. link = item.text
  145. if link in links:
  146. pass
  147. else:
  148. if index != 0:
  149. if region.lower() == "uk" :
  150. pid = link.split("/")[4].split(".html")[0]
  151. if region.lower() == "us" or region.lower() == "ca":
  152. pid = link.split("/")[5].split(".html")[0]
  153. title = gettitle(link, region)
  154. if useproxies == False:
  155. data = getdata(pid, suggestionsbase, False, "")
  156. try:
  157. discordpost(title, data, link, webhook, False, "")
  158. except:
  159. print("Error posting to discord, make sure you have entered your webhook")
  160. else:
  161. data = getdata(pid, suggestionsbase, True, proxies)
  162. try:
  163. discordpost(title, data, link, webhook, True, proxies)
  164. except:
  165. print("Error posting to discord, make sure you have entered your webhook")
  166.  
  167. print("--------------\nFound new item: \nTitle: %s\nPrice: %s\nLink: %s\n---------------\n" %(title,data[0],link))
  168. links.append(link)
  169. foundnewlink = True
  170. if index == 0:
  171. print("Loaded products")
  172. if foundnewlink == False:
  173. print("No new links found")
  174. time.sleep(interval)
  175. index += 1
  176. loop(index,links,map,useproxies,rawproxies,region)
  177.  
  178. loop(0,links,map,useproxies,rawproxies,region)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement