-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
267 lines (223 loc) · 9.28 KB
/
main.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import requests
import time
import random
from urllib.parse import unquote
import threading
import json
import re
from autoplay import autoplay
default_header = {
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
"origin": "https://telegram.blum.codes",
"authorization": "",
"priority": "u=1, i",
"sec-ch-ua": '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128", "Microsoft Edge WebView2";v="128"',
"sec-ch-ua-platform": "Windows",
"sec-ch-ua-mobile": "?0",
"user-agent": "Mozilla/5.0 (Linux; Android 15; SM-A102U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.6613.127 Mobile Safari/537.36",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty"
}
def send_request(acc_name, url, method, headers, data = None):
access_token = (accounts.get(acc_name)).get("access_token")
headers.update({
'authorization': access_token
})
method = method.upper()
if method == "POST":
if data:
response = requests.post(url, headers=headers, data=data)
else:
response = requests.post(url, headers=headers)
elif method == "GET":
response = requests.get(url, headers=headers)
return response
def startFarm(acc_name):
print(f"[{acc_name}] starting farm =>", end="")
url = "https://game-domain.blum.codes/api/v1/farming/start"
access_token = (accounts.get(acc_name)).get("access_token")
headers = default_header.copy()
headers.update({
'authorization': access_token
})
# response = send_request(acc_name, url, "POST", default_header.copy)
response = requests.post(url, headers=headers)
print(" response: ", response)
def claim_farm(acc_name):
print(f"[{acc_name}] => Claim Farm =>", end="")
url = 'https://game-domain.blum.codes/api/v1/farming/claim'
access_token = (accounts.get(acc_name)).get("access_token")
headers = default_header.copy()
headers.update({
'authorization': access_token
})
# response = send_request(acc_name, url, "POST", default_header.copy)
response = requests.post(url, headers=headers)
print("response: ", response)
return response.json()
def get_daily_reward(acc_name):
print(f"[{acc_name}] getting Daily reward => ", end="")
url = 'https://game-domain.blum.codes/api/v1/daily-reward?offset=-210'
response_get = send_request(acc_name, url, "GET", default_header)
response_js = response_get.json()
if response_js.get('days'):
print(f"[{acc_name}] => daily reward: {response_js}")
response = send_request(acc_name, url, "POST", default_header)
else:
print(f"[{acc_name}] => daily reward not found")
def user_balance(acc_name):
url = "https://game-domain.blum.codes/api/v1/user/balance"
response = send_request(acc_name, url, "GET", default_header)
print(f"[{acc_name}] => user balance: {response.json().get('availableBalance')}")
return response.json()
def login(acc_name):
print("Logging into Account", acc_name)
url = "https://user-domain.blum.codes/api/v1/auth/provider/PROVIDER_TELEGRAM_MINI_APP"
global accounts
auth_url = (accounts.get(acc_name)).get("auth_url")
if "https://telegram.blum.codes" in auth_url:
auth_url = auth_url.replace("https://telegram.blum.codes/#tgWebAppData=", "")
decode_data = unquote(string=unquote(string=auth_url.split('&tgWebAppVersion')[0]))
json_data = {"query": decode_data}
response = requests.post(url, json=json_data)
response_json = response.json()
ref_token = response_json.get("token").get("refresh")
access_token = "Bearer " + response_json.get("token").get("access")
accounts[acc_name].update({
"access_token": access_token,
"refresh_token": ref_token,
"login": True
})
return ref_token, access_token
def refreshToken(acc_name):
global accounts
ref_token = accounts[acc_name]["refresh_token"]
refresh_payload = {
"refresh": ref_token
}
response = requests.post(
"https://user-domain.blum.codes/api/v1/auth/refresh",
json=refresh_payload
)
if response.ok:
data = response.json()
new_access_token = data.get("access")
new_refresh_token = data.get("refresh")
if new_access_token:
accounts[acc_name].update({
"refresh_token": new_refresh_token,
"access_token": new_access_token
})
print("Token refreshed successfully")
else:
print("New access token not found in the response")
else:
print("Failed to refresh the token")
def read_from_file():
with open("url.txt", "r") as f:
return f.readlines()
def main(acc_name):
while True:
try:
with open("config.json", 'r') as file:
config = json.load(file)
except Exception as e:
print("Failed to read config.json or file does not exist.")
exit(1)
try:
if not accounts.get(acc_name).get("login"):
login(acc_name)
user_data = user_balance(acc_name)
if user_data.get("message") == "Invalid jwt token":
print("Invalid Token, refreshing token")
login(acc_name)
user_data = user_balance(acc_name)
time.sleep(random.uniform(6, 10))
get_daily_reward(acc_name)
timestamp = user_data.get("timestamp", None)
farmingtime = user_data.get("farming", None)
end_time = farmingtime.get("endTime", None) if farmingtime else None
if (user_data.get("farming", None) is None) or (timestamp and end_time and timestamp >= end_time):
claim_farm(acc_name)
time.sleep(random.uniform(2, 10))
startFarm(acc_name)
time.sleep(random.uniform(2, 10))
get_daily_reward(acc_name)
time.sleep(random.uniform(2, 10))
user_data = user_balance(acc_name)
timestamp = user_data.get("timestamp", None)
elif end_time and timestamp < end_time:
time_to_farm = (end_time // 1000) - (timestamp // 1000)
hour = time_to_farm // 3600
minute = (time_to_farm - (hour * 3600)) // 60
second = time_to_farm - (hour * 3600) - (minute * 60)
card_number = user_data.get("playPasses")
if card_number > 0 and config.get("auto_play_game") and False:
print("available tickets count => ", card_number)
max_tiket = config.get("max_ticket_use")
if card_number <= 3:
iter = card_number
elif card_number > 3:
if max_tiket <= 3:
iter = max_tiket
elif max_tiket <= card_number:
iter = random.randint(max_tiket - 3, max_tiket)
else:
iter = random.randint(card_number - 3, card_number)
print(f"count for iter is {iter}")
autoplay(
accounts, acc_name, iter,
config.get("game_point").get("low"),
config.get("game_point").get("high")
)
print(
f"account: {acc_name}, Balance: {user_data.get('availableBalance')},"
f" Card Number: {user_data.get('playPasses')}",
f"End time of farming in {hour} hour, {minute} minute, {second} seconds"
)
delay = random.uniform(time_to_farm + 1, time_to_farm + (6 * 60))
print(f"add random time to sleep {delay} seconds")
time.sleep(delay)
login(acc_name)
else:
print(f"[{acc_name}] => unknown condition!")
print(f"[{acc_name}] user reported balance json: ", user_data)
except Exception as e:
print(f"error => {e}")
user_data = user_balance(acc_name)
continue
def start_threads():
threads = []
for acc in accounts.keys():
process = threading.Thread(target=main, args=(acc,))
threads.append(process)
process.start()
time.sleep(random.uniform(10, 20))
for thread in threads:
thread.join()
if __name__ == "__main__":
print("Development By Reza")
accounts = {}
links = read_from_file()
if not links or links[0].strip() == "":
print("please insert your link in url.txt")
exit()
for x in links:
x = x.strip()
decode_data = unquote(string=unquote(string=x.split('&tgWebAppVersion')[0]))
match = re.search(r'"id":(\d+)', decode_data)
name = re.search(r'"first_name":"(.*?)"', decode_data)
if match:
user_id = match.group(1)
name = name.group(1) if name else user_id
name = f"{user_id} {name}"
accounts[name] = {
"auth_url": decode_data,
"access_token": "",
"refresh_token": "refresh_token",
"login": False,
}
# main(name)
start_threads()