Last active
May 15, 2019 17:54
-
-
Save alxgmpr/ec41b78057bec3688fb97f4782a41a5b to your computer and use it in GitHub Desktop.
Hunting around with Target's e-comm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime | |
from time import sleep | |
import threading | |
class Target(threading.Thread): | |
def __init__(self, tid): | |
self.tid = tid | |
threading.Thread.__init__(self) | |
self.slackhook = 'https://hooks.slack.com/services/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' | |
def log(self, text): | |
timestamp = datetime.now().strftime('%H:%M:%S') | |
print '[{}] :: {}'.format(timestamp, text) | |
def slack(self, text): | |
data = { | |
"attachments": [{ | |
"fallback": "TARGET NES ADDED TO CART", | |
"color": "#36a64f", | |
"author_name": "Thread {}".format(self.tid), | |
"text": text | |
}] | |
} | |
def wait(): | |
log('waiting before refreshing') | |
sleep(5.0) | |
def tryatc(): | |
log('attempting to add to cart') | |
endpoint = 'https://www-secure.target.com/api/cart/order-api/cart/v5/cartitems?responseGroup=cart' | |
payload = { | |
"products": [{ | |
"partnumber": "52826093", | |
"quantity": "1" | |
}] | |
} | |
while True: | |
try: | |
r.raise_for_status() | |
self.slack('!!!!!!!!!!!!!!SUCCESFULLY ADDED. STOCK LIVE.!!!!!!!!!!!!!') | |
break | |
except requests.exceptions.HTTPError: | |
self.log('still out of stock :(') | |
print r.text | |
wait() | |
self.add_to_cart() | |
def run(self): | |
while True: | |
self.tryatc() | |
t = Target() | |
t.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment