@@ -44,6 +44,10 @@ def load_accounts():
44
44
if 'cookies' not in account or 'api_user' not in account :
45
45
print (f'ERROR: Account { i + 1 } missing required fields (cookies, api_user)' )
46
46
return None
47
+ # 如果有 name 字段,确保它不是空字符串
48
+ if 'name' in account and not account ['name' ]:
49
+ print (f'ERROR: Account { i + 1 } name field cannot be empty' )
50
+ return None
47
51
48
52
return accounts_data
49
53
except Exception as e :
@@ -73,10 +77,17 @@ def save_balance_hash(balance_hash):
73
77
74
78
def generate_balance_hash (balances ):
75
79
"""生成余额数据的hash"""
76
- balance_json = json .dumps (balances , sort_keys = True , separators = (',' , ':' ))
80
+ # 将包含 quota 和 used 的结构转换为简单的 quota 值用于 hash 计算
81
+ simple_balances = {k : v ['quota' ] for k , v in balances .items ()} if balances else {}
82
+ balance_json = json .dumps (simple_balances , sort_keys = True , separators = (',' , ':' ))
77
83
return hashlib .sha256 (balance_json .encode ('utf-8' )).hexdigest ()[:16 ]
78
84
79
85
86
+ def get_account_display_name (account_info , account_index ):
87
+ """获取账号显示名称"""
88
+ return account_info .get ('name' , f'Account { account_index + 1 } ' )
89
+
90
+
80
91
def parse_cookies (cookies_data ):
81
92
"""解析 cookies 数据"""
82
93
if isinstance (cookies_data , dict ):
@@ -180,7 +191,7 @@ def get_user_info(client, headers):
180
191
181
192
async def check_in_account (account_info , account_index ):
182
193
"""为单个账号执行签到操作"""
183
- account_name = f'Account { account_index + 1 } '
194
+ account_name = get_account_display_name ( account_info , account_index )
184
195
print (f'\n [PROCESSING] Starting to process { account_name } ' )
185
196
186
197
# 解析账号配置
@@ -308,27 +319,31 @@ async def main():
308
319
if not success :
309
320
should_notify_this_account = True
310
321
need_notify = True
311
- print (f'[NOTIFY] Account { i + 1 } failed, will send notification' )
322
+ account_name = get_account_display_name (account , i )
323
+ print (f'[NOTIFY] { account_name } failed, will send notification' )
312
324
313
325
# 收集余额数据
314
326
if user_info and user_info .get ('success' ):
315
327
current_quota = user_info ['quota' ]
316
- current_balances [account_key ] = current_quota
328
+ current_used = user_info ['used_quota' ]
329
+ current_balances [account_key ] = {'quota' : current_quota , 'used' : current_used }
317
330
318
331
# 只有需要通知的账号才收集内容
319
332
if should_notify_this_account :
333
+ account_name = get_account_display_name (account , i )
320
334
status = '[SUCCESS]' if success else '[FAIL]'
321
- account_result = f'{ status } Account { i + 1 } '
335
+ account_result = f'{ status } { account_name } '
322
336
if user_info and user_info .get ('success' ):
323
337
account_result += f'\n { user_info ["display" ]} '
324
338
elif user_info :
325
339
account_result += f'\n { user_info .get ("error" , "Unknown error" )} '
326
340
notification_content .append (account_result )
327
341
328
342
except Exception as e :
329
- print (f'[FAILED] Account { i + 1 } processing exception: { e } ' )
343
+ account_name = get_account_display_name (account , i )
344
+ print (f'[FAILED] { account_name } processing exception: { e } ' )
330
345
need_notify = True # 异常也需要通知
331
- notification_content .append (f'[FAIL] Account { i + 1 } exception: { str (e )[:50 ]} ...' )
346
+ notification_content .append (f'[FAIL] { account_name } exception: { str (e )[:50 ]} ...' )
332
347
333
348
# 检查余额变化
334
349
current_balance_hash = generate_balance_hash (current_balances ) if current_balances else None
@@ -351,11 +366,12 @@ async def main():
351
366
for i , account in enumerate (accounts ):
352
367
account_key = f'account_{ i + 1 } '
353
368
if account_key in current_balances :
369
+ account_name = get_account_display_name (account , i )
354
370
# 只添加成功获取余额的账号,且避免重复添加
355
- account_result = f'[BALANCE] Account { i + 1 } '
356
- account_result += f'\n :money: Current balance: ${ current_balances [account_key ]} '
371
+ account_result = f'[BALANCE] { account_name } '
372
+ account_result += f'\n :money: Current balance: ${ current_balances [account_key ][ "quota" ] } , Used: $ { current_balances [ account_key ][ "used" ] } '
357
373
# 检查是否已经在通知内容中(避免重复)
358
- if not any (f'Account { i + 1 } ' in item for item in notification_content ):
374
+ if not any (account_name in item for item in notification_content ):
359
375
notification_content .append (account_result )
360
376
361
377
# 保存当前余额hash
0 commit comments