-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
230 lines (210 loc) · 9.52 KB
/
main.py
File metadata and controls
230 lines (210 loc) · 9.52 KB
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
"""
TO DO:
- Find payment id automatically
- Make monitor and integrate with Slack
- Make this look all professional and shit with classes and logging instead some shitty printing
"""
import requests
import bs4 as bs
import simplejson as json
# importing * is bad practice, i know, go away
from decimal import *
import datetime
from urllib.parse import quote
import time
r = requests.session()
host = 'https://www.boxlunch.com/'
# if you're not using logging, this is the dumb shit you do instead
def get_timestamp():
t = str(datetime.datetime.now())
return t
config = open('config.json')
configdump = json.load(config)
loginemail = configdump['loginemail']
loginemaildontatme = quote(loginemail)
loginpass = configdump['loginpass']
# make sure card is default on account
paymentinfo = configdump['paymentinfo']
# Add product url and product id - product url not used at the moment
producturl = configdump['earlylink']
productid = configdump['productid']
quantity = configdump['quantity']
atcurl = 'https://www.boxlunch.com/on/demandware.store/Sites-boxlunch-Site/default/Product-CLPAdd2Cart?cgid=undefined&pid={}&Quantity=1&format=ajax'.format(productid)
headersmain = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9,fr;q=0.8,es;q=0.7',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
}
headersmobileguest = {
'Host': 'cloudservices.predictspring.com',
'PredictSpring-InstallationID': 'bb40bc24-defe-4a08-a4ff-1aed95038565',
'Accept': 'application/json',
'PredictSpring-Region': 'US',
'PredictSpring-API-Key': 'afgNO1L6P2IwRegfmJFZI575',
'PredictSpring-Locale': 'en_US',
'PredictSpring-DeviceName': 'FunkoFucked',
'PredictSpring-MerchantID': 'BOXLUNCH672907',
'User-Agent': 'BoxLunch/3798 CFNetwork/901.1 Darwin/17.6.0',
'Content-Type': 'application/json'
}
# def productscrape(url):
# product = r.get(producturl, headers = headersmain)
# soup = bs.BeautifulSoup(product.text, 'lxml')
# productname = soup.find('h1', {'itemprop': 'name'})
# print(productname)clear
# soon (TM)
def login(email, password):
loginurl = 'https://cloudservices.predictspring.com/search/v1/customer/login'
payload = {
"credentials":{
"password": password,
"userId": email,
"userIdType":"EMAIL"
},
"includeCart": "true",
"includeProfile": "true"
}
login = r.post(loginurl, json = payload, headers = headersmobileguest)
print('[' + get_timestamp() + '] Follow me on Twitter - @TaquitoSlayer')
print('[' + get_timestamp() + '] Do not forget to tell your momma that FUNKO FUCKED TOOK STOCK')
print('[' + get_timestamp() + '] LOGGED IN WITH {}'.format(email))
return login.text
# imagine being shit at code and using 1 entire function to checkout - im a bio major, fuck off :)
def main():
# login and grab saved addy and other info for checkout
login_return = login(loginemail, loginpass)
try:
jsondump = json.loads(login_return)
sessionid = jsondump['sessionId']
profile = jsondump['profile']
customerid = profile['customerId']
addresslist = jsondump['addressList']
except:
print('[' + get_timestamp() + '] Login error found! - printing response:')
print(login_return)
# once logged in, different header needed
headersmobilecustomer = {
'PredictSpring-SessionId': sessionid,
'PredictSpring-Attribution': '%7B%22email%22%3A%22{}%22%2C%22customerGroups%22%3A%5B%22BoxLunch_5Star%22%2C%22Everyone%22%2C%22Non-Employees%22%2C%22Registered%22%5D%7D'.format(loginemaildontatme),
'PredictSpring-CustomerGroups': 'BoxLunch_5Star|Everyone|Non-Employees|Registered',
'PredictSpring-Region': 'CA',
'PredictSpring-API-Key': 'afgNO1L6P2IwRegfmJFZI575',
'PredictSpring-MerchantId': 'BOXLUNCH672907',
'PredictSpring-Locale': 'en_CA',
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; Pixel 2 XL Build/OPM2.171019.029) FUNKOFUCKEDTOOKSTOCK',
'Host': 'cloudservices.predictspring.com',
'Accept-Encoding': 'gzip',
}
addtocarturl = 'https://cloudservices.predictspring.com/search/v1/customer/{}/cart/product/update'.format(customerid)
carturl = 'https://cloudservices.predictspring.com/search/v1/customer/{}/cart'.format(customerid)
payload = {
"adjustedQuantity":0,
"cartItemList":[],
"isGift": 'false',
"newQuantity": quantity,
"oneTimePromotionCodes":[],
"productId": productid,
"promotionCodes":[],
"session": sessionid}
add = r.post(addtocarturl, json = payload, headers = headersmobilecustomer)
print('[' + get_timestamp() + '] PRODUCT ADDED TO CART')
# Most info needed for placing order comes from add.text
# why does json in python convert decimal values when not asked to?
jsondump = json.loads(add.text, use_decimal=True)
cartitemlist = jsondump['cartItemList']
price = jsondump['subTotal']
price = json.dumps(price, use_decimal=True)
# On app, selecting cart makes an initial request for info - It's most likely redundant.
payload_orderpullup = {
"cartItemList": cartitemlist,
"customerGroups":["BoxLunch_5Star","Everyone", "Non-Employees", "Registered"],
"customerId": customerid,
"rewardList":[],
"customerEmail": loginemail,
"giftCardList":[],
"installationId":"fb04e0df-13f8-493f-b3cd-f3de91a13d54",
"isGift":'false',
"oneTimePromotionCodes":[],
"productList":[],
"promotionCodes":[],
"shippingAddress": addresslist[0]
}
orderpullup = r.post(addtocarturl, json = payload_orderpullup, headers = headersmobilecustomer)
jsondump = json.loads(orderpullup.text)
sessionid = jsondump['session']
# For whatever reason, demandware-mobileapi likes to make 2 request of pretty much the exact things in the payload, except for 1-3 new key and value added
# When submitting this, it creates an order which when made, essentially the product is yours, you just need to pay.
for cartitemlists in cartitemlist:
cartitemlists['variantGroupId'] = productid
cartitemlists['adjustedQuantity'] = '0'
cartitemlists['oldQuantity'] = '0'
cartitemlists['price'] = price
payload_orderinit = {
"cartItemList": cartitemlist,
"customerGroups":["BoxLunch_5Star","Everyone", "Non-Employees", "Registered"],
"customerId": customerid,
"rewardList":[],
"customerEmail": loginemail,
"giftCardList":[],
"installationId":"fb04e0df-13f8-493f-b3cd-f3de91a13d54",
"isGift":'false',
"oneTimePromotionCodes":[],
"productList":[],
"promotionCodes":[],
"shippingAddress": addresslist[0]
}
add_orderinit = r.post(carturl, json = payload_orderinit, headers = headersmobilecustomer)
# final order - get hit with these shitty variable names that don't follow pep8
jsondump = json.loads(add_orderinit.text, use_decimal=True)
shippingmethod = jsondump['shippingMethodList']
shippingmethodid = shippingmethod[0]['shippingMethodId']
shippingprice = shippingmethod[0]['price']
shippingtax = shippingmethod[0]['tax']
# gay ass decimal shit
getcontext().prec = 47
grandtotal = Decimal(shippingprice) + Decimal(price) + Decimal(shippingtax)
print('[' + get_timestamp() + '] GRAND TOTAL: ', grandtotal)
payload_orderfinal = {
"billingAddress": addresslist[0],
"cartId": "this",
"customerEmail": loginemail,
"customerId": customerid,
"rewardList": [],
"giftCardList": [],
"grandTotal": str(grandtotal),
"installationId": "fb04e0df-13f8-493f-b3cd-f3de91a13d54",
"isGift": 'false',
"oneTimePromotionCodes": [],
"paymentData": {
"paymentCard": paymentinfo,
"paymentType": "StoredCard"
},
"productList": cartitemlist,
"promotionCodes": [],
"shippingAddress": addresslist[0],
"shippingMethodId": shippingmethodid,
"storeId": ""
}
# i heard project destroyer cant even push payment through properly :P
final = 'https://cloudservices.predictspring.com/search/v1/customer/{}/cart/this/submit'.format(customerid)
finalcheckout = r.post(final, json = payload_orderfinal, headers = headersmobilecustomer)
print('[' + get_timestamp() + '] ' + finalcheckout.text)
# let's buttfuck at 213132321312213 requests/second and if it times out TOO FUCKING BAD WE GUNNA KEEP FUCKING IT TILL BOXLUNCH'S CAREER IS LISA ANN
while True:
# could make this a seperate function but it's already done and i got lazy - it's basically a monitor in 5-10 lines of code
checkifavail = r.get(atcurl, headers = headersmain)
soup = bs.BeautifulSoup(checkifavail.text, 'lxml')
inventory = soup.find('input', {'name': 'hasInventory'}).get('value')
if inventory == 'false':
print('[' + get_timestamp() + '] NOT IN STOCK, MONITORING...')
# where were you when i didnt add proper exception handling for connection handling which almost happens all the time ;)
time.sleep(1.5)
elif inventory == 'true':
print('[' + get_timestamp() + '] STOCK FOUND')
print('[' + get_timestamp() + '] CHECKING OUT NOW')
main()
break