Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.

Commit 7930eaf

Browse files
authored
Create main.py
1 parent c42d5ce commit 7930eaf

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

main.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import requests
2+
import json
3+
import os
4+
5+
fp_cart_id = ''
6+
jd_cart_id = ''
7+
sz_cart_id = ''
8+
9+
def cls():
10+
os.system('cls' if os.name=='nt' else 'clear')
11+
12+
class MeshAPI(object):
13+
def __init__(self, site):
14+
cls()
15+
16+
self.s = requests.Session()
17+
self.site = site.upper()
18+
19+
print "MeshAPI by Luke Davis (@R8T3D) | Site: " + self.site
20+
print "="*60
21+
22+
if self.site == 'FP':
23+
self.api_key = '5F9D749B65CD44479C1BA2AA21991925'
24+
self.user_agent = 'FootPatrol/2.0 CFNetwork/808.3 Darwin/16.3.0'
25+
self.cart_id = str(fp_cart_id)
26+
self.sitename = 'footpatrol'
27+
28+
elif self.site == 'JD':
29+
self.api_key = '1A17CC86AC974C8D9047262E77A825A4'
30+
self.user_agent = 'JDSports/5.3.1.207 CFNetwork/808.3 Darwin/16.3.0'
31+
self.cart_id = str(jd_cart_id)
32+
self.sitename = 'jdsports'
33+
34+
elif self.site == 'SZ':
35+
self.api_key = 'EA0E72B099914EB3BA6BE90A21EA43A9'
36+
self.user_agent = 'Size-APPLEPAY/4.0 CFNetwork/808.3 Darwin/16.3.0'
37+
self.cart_id = str(sz_cart_id)
38+
self.sitename = 'size'
39+
40+
self.headers = {
41+
'Host': 'commerce.mesh.mx',
42+
'Content-Type': 'application/json',
43+
'X-API-Key': self.api_key,
44+
'Accept': '*/*',
45+
'X-Debug': '1',
46+
'Accept-Language': 'en-gb',
47+
'User-Agent': self.user_agent,
48+
'MESH-Commerce-Channel': 'iphone-app',
49+
}
50+
51+
self.s.get('https://commerce.mesh.mx/stores/' + self.sitename + '/carts/' + self.cart_id, headers=self.headers)
52+
53+
def get_product_info(self, pid):
54+
pid = str(pid)
55+
56+
params = (
57+
('expand', 'variations,informationBlocks,customisations'),
58+
('channel', 'iphone-app'),
59+
)
60+
61+
stock_json_raw = self.s.get('https://commerce.mesh.mx/stores/' + self.sitename + '/products/' + pid, headers=self.headers, params=params).text.strip()
62+
stock_json = json.loads(stock_json_raw)
63+
64+
try:
65+
product_name = str(stock_json['name'])
66+
print product_name
67+
for size in stock_json['options']:
68+
print size + ": " + stock_json['options'][size]['SKU']
69+
except:
70+
print "Error finding product"
71+
72+
choice = raw_input("Product appears to be in stock. \nAttempt to add product to cart? (Y/N) ")
73+
if choice.upper() == "Y":
74+
self.add_to_cart(pidsize)
75+
76+
def add_to_cart(self, pidsize):
77+
pidsize = str(pidsize)
78+
79+
if self.site == 'JD':
80+
data = '{"contents":[{"$schema":"https:\\/\\/commerce.mesh.mx\\/stores\\/jdsports\\/schema\\/CartProduct","SKU":"' + pidsize + '","quantity":1}]}'
81+
82+
ATC = self.s.put('https://commerce.mesh.mx/stores/jdsports/carts/' + self.cart_id, headers=self.headers, data=data)
83+
else:
84+
ATC = self.s.put('https://commerce.mesh.mx/stores/' + self.sitename + '/carts/' + self.cart_id + '/' + pidsize, headers=self.headers, data='{"quantity":1}')
85+
86+
print "Status Code: " + str(ATC.status_code)
87+
print "ATC success."
88+
89+
if __name__ == '__main__':
90+
cls()
91+
print "MeshAPI by Luke Davis (@R8T3D)"
92+
print "="*60
93+
94+
site = raw_input('Site? (FP, JD, SZ) ')
95+
mesh = MeshAPI(site)
96+
97+
choice = raw_input("What would you like to do? (ATC or INFO) ")
98+
if choice.upper() == "ATC":
99+
pidsize = raw_input("PID.SIZE? ")
100+
mesh.add_to_cart(pidsize)
101+
else:
102+
pid = raw_input("PID? ")
103+
mesh.get_product_info(pid)

0 commit comments

Comments
 (0)