-
Notifications
You must be signed in to change notification settings - Fork 2
/
themarket_discount_codes.py
166 lines (157 loc) · 3.95 KB
/
themarket_discount_codes.py
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
from tqdm import tqdm
from datetime import datetime
import json
import subprocess
import time
def test_coupon_code(code):
curl_command = [
"curl",
"https://themarket.com/api/coupon/fe/check",
"-X",
"POST",
"-H",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0",
"-H",
"Accept: application/json",
"-H",
"Accept-Language: en-GB,en;q=0.5",
"-H",
"Accept-Encoding: gzip, deflate, br",
"-H",
"Referer: https://themarket.com/nz/checkout",
"-H",
"Access-Token: YOUR_TOKEN",
"-H",
"Content-Type: application/json",
"-H",
"Origin: https://themarket.com",
"-H",
"DNT: 1",
"-H",
"Connection: keep-alive",
"-H",
"Cookie: YOUR_COOKIE",
"-H",
"Sec-Fetch-Dest: empty",
"-H",
"Sec-Fetch-Mode: cors",
"-H",
"Sec-Fetch-Site: same-origin",
"-H",
"TE: trailers",
"--data-raw",
f'{{"CultureCode":"EN","CouponReference":"{code}","MerchantId":0}}',
]
process = subprocess.Popen(
curl_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, stderr = process.communicate()
if process.returncode == 0:
return stdout.decode("utf-8")
else:
# Handling the case if curl command itself fails.
return f"Error: {stderr.decode('utf-8')}"
codes = [
"5XMAS",
"10XMAS",
"15XMAS",
"5LABOUR",
"10LABOUR",
"15LABOUR",
"APRCLUB",
"AUGCLUB",
"AUTUMN5",
"AUTUMN10",
"BXD5",
"CLUB5",
"CLUB5DEC",
"CLUB10",
"CLUB10A",
"CLUB10B",
"CLUB15",
"CLUBJOY",
"CLUBPERKS",
"CLUBRMHC",
"CLUBSAVE",
"CLUBSAVE5",
"CLUBSAVE10",
"CLUBSAVER",
"DECCLUB",
"DONE5",
"DONE10",
"EASTER5",
"EASTER10",
"EXCLU10",
"EXCLUSIVE10",
"FEBCLUB",
"FEST",
"GET5",
"JANCLUB",
"JUBILEE5",
"JUBILEE8",
"JUBILEE10",
"JULCLUB",
"JUNCLUB",
"KING10",
"KIWI5",
"KIWI10",
"LUCKY13",
"MARCLUB",
"MAYCLUB",
"MC5",
"MC10",
"MC15",
"MCLUB5",
"MCLUB10",
"MCLUB11",
"MCLUB15",
"MCLUB20",
"MCLUB30",
"NOVCLUB",
"NYMC10",
"OCTCLUB",
"SASDEC23",
"SAVE5",
"SAVE10",
"SAVING5",
"SAVING10",
"SAVING20",
"SAVING30",
"SAVVY10",
"SEPCLUB",
"SORTED5",
"SORTED10",
"SORTED15",
"SPRING5",
"SPRING10",
"SUMMER5",
"SUMMER10",
"WEEKEND5",
"WEEKEND10",
"WKND5",
"WKND10",
] # Replace with your list of codes
print("Number of codes to check: " + str(len(codes)))
for code in tqdm(codes):
response = test_coupon_code(code)
response_data = json.loads(response)
time.sleep(30)
if "AppCode" in response_data:
print(f"Code: {code}")
else:
available_from = response_data.get("AvailableFrom", "N/A")
available_to = response_data.get("AvailableTo", "N/A")
coupon_amount = response_data.get("CouponAmount", "N/A")
coupon_percent = response_data.get("CouponPercent", "N/A")
coupon_reference = response_data.get("CouponReference", "N/A")
if available_to != "N/A":
available_to_date = datetime.strptime(available_to, "%Y-%m-%dT%H:%M:%S.%f")
if available_to_date.date() > datetime.now().date():
valid_status = " - VALID!"
else:
valid_status = ""
else:
valid_status = ""
print(
f"Code: {code} - Available From: {available_from}, Available To: {available_to}, Coupon Amount: {coupon_amount}, Coupon Percent: {coupon_percent}, Coupon Reference: {coupon_reference}{valid_status}"
)