-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.py
171 lines (144 loc) · 6.88 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
import aiohttp
import asyncio
import aiofiles
import logging
import time
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# 设置默认请求头
headers = {
'Content-Type': 'application/json',
}
# coday 函数
async def coday(url, method, headers, payload_data=None, proxy=None):
try:
async with aiohttp.ClientSession() as session:
async with session.request(method, url, headers=headers, json=payload_data, proxy=proxy) as response:
try:
json_data = await response.json()
except aiohttp.ContentTypeError:
json_data = {}
if not response.ok:
return {'error': True, 'status': response.status, 'data': json_data}
return json_data
except Exception as e:
logger.error(f"Error in coday: {e}")
return {'error': True, 'message': str(e)}
# 读取令牌、唯一 ID 和代理
async def read_tokens_ids_and_proxies():
try:
# 读取 token 文件
async with aiofiles.open('token.txt', 'r') as f:
token_data = await f.read()
tokens = [line.strip() for line in token_data.split('\n') if line.strip()]
# 读取唯一 ID 文件
async with aiofiles.open('unique_id.txt', 'r') as f:
ids_data = await f.read()
unique_ids = [line.strip() for line in ids_data.split('\n') if line.strip()]
# 询问用户是否使用代理
use_proxy = input("是否使用代理?(y/n): ").strip().lower() == 'y'
proxies = []
if use_proxy:
# 读取代理文件
async with aiofiles.open('proxy.txt', 'r') as f:
proxy_data = await f.read()
proxies = [line.strip() for line in proxy_data.split('\n') if line.strip()]
# 检查 token、唯一 ID 和代理的行数是否匹配
if len(tokens) != len(unique_ids) or len(tokens) != len(proxies):
logger.error("Token、唯一 ID 和代理的行数不匹配。")
return []
# 组合账户信息
accounts = []
for i in range(len(tokens)):
access_token, refresh_token = map(str.strip, tokens[i].split('|'))
ids = list(map(str.strip, unique_ids[i].split('|')))
proxy = proxies[i] if use_proxy else None
proxy_type = 'socks5' if proxy and proxy.startswith('socks5://') else 'http'
accounts.append({'access_token': access_token, 'refresh_token': refresh_token, 'unique_ids': ids, 'proxy': f"{proxy_type}://{proxy}" if proxy else None})
return accounts
except Exception as e:
logger.error(f"读取 token、唯一 ID 或代理文件失败: {e}")
return []
# 刷新令牌功能
async def refresh_token(refresh_token, account_index, proxy):
logger.info(f"正在刷新账户 {account_index + 1} 的访问令牌...")
payload_data = {'refresh_token': refresh_token}
response = await coday("https://api.meshchain.ai/meshmain/auth/refresh-token", 'POST', headers, payload_data, proxy=proxy)
if response and response.get('access_token'):
# 更新 token 文件
async with aiofiles.open('token.txt', 'r') as f:
token_lines = (await f.read()).split('\n')
token_lines[account_index] = f"{response['access_token']}|{response['refresh_token']}"
async with aiofiles.open('token.txt', 'w') as f:
await f.write('\n'.join(token_lines))
logger.info(f"账户 {account_index + 1} 的令牌刷新成功")
return response['access_token']
logger.error(f"账户 {account_index + 1} 的令牌刷新失败")
return None
# info 函数
async def info(unique_id, headers, proxy):
url = 'https://api.meshchain.ai/meshmain/nodes/status'
return await coday(url, 'POST', headers, {'unique_id': unique_id}, proxy=proxy)
# estimate 函数
async def estimate(unique_id, headers, proxy):
url = 'https://api.meshchain.ai/meshmain/rewards/estimate'
return await coday(url, 'POST', headers, {'unique_id': unique_id}, proxy=proxy)
# claim 函数
async def claim(unique_id, headers, proxy):
url = 'https://api.meshchain.ai/meshmain/rewards/claim'
result = await coday(url, 'POST', headers, {'unique_id': unique_id}, proxy=proxy)
return result.get('total_reward', None)
# start 函数
async def start(unique_id, headers, proxy):
url = 'https://api.meshchain.ai/meshmain/rewards/start'
return await coday(url, 'POST', headers, {'unique_id': unique_id}, proxy=proxy)
# 单个账户的主要处理流程
async def process_account(account, account_index):
global headers
headers['Authorization'] = f"Bearer {account['access_token']}"
for unique_id in account['unique_ids']:
proxy = account['proxy']
# 获取用户信息
profile = await info(unique_id, headers, proxy)
if profile.get('error'):
logger.error(f"账户 {account_index + 1} | {unique_id}: 获取用户信息失败,尝试刷新令牌...")
new_access_token = await refresh_token(account['refresh_token'], account_index, proxy)
if not new_access_token:
return
headers['Authorization'] = f"Bearer {new_access_token}"
else:
name = profile.get('name')
total_reward = profile.get('total_reward')
logger.info(f"账户 {account_index + 1} | {unique_id}: {name} | 余额: {total_reward}")
# 获取奖励估算
filled = await estimate(unique_id, headers, proxy)
if not filled:
logger.error(f"账户 {account_index + 1} | {unique_id}: 获取估算值失败。")
continue
if filled.get('value', 0) > 10:
logger.info(f"账户 {account_index + 1} | {unique_id}: 尝试领取奖励...")
reward = await claim(unique_id, headers, proxy)
if reward:
logger.info(f"账户 {account_index + 1} | {unique_id}: 奖励领取成功!新余额: {reward}")
await start(unique_id, headers, proxy)
logger.info(f"账户 {account_index + 1} | {unique_id}: 重新开始挖矿。")
else:
logger.error(f"账户 {account_index + 1} | {unique_id}: 领取奖励失败。")
else:
logger.info(f"账户 {account_index + 1} | {unique_id}: 已经在挖矿中,当前值: {filled.get('value', 0)}")
# 主流程处理所有账户
async def main():
banner = "Your Banner Here"
logger.debug(banner)
while True:
accounts = await read_tokens_ids_and_proxies()
if not accounts:
logger.error("没有账户可处理。")
return
for i, account in enumerate(accounts):
logger.info(f"正在处理账户 {i + 1}...")
await process_account(account, i)
await asyncio.sleep(60) # 每 60 秒运行一次
# 运行主流程
if __name__ == "__main__":
asyncio.run(main())