From 42b86a78d214ee85c29983e2b1902b10b1c61438 Mon Sep 17 00:00:00 2001 From: Wong Yiek Heng Date: Sun, 5 Oct 2025 09:15:58 +0800 Subject: [PATCH] + Add thread info + Remove N/A from web view when result is empty --- cm_transfer_credit.py | 19 ++++++++++--------- cm_web_view.py | 18 +++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cm_transfer_credit.py b/cm_transfer_credit.py index 69efb2b..75952b2 100644 --- a/cm_transfer_credit.py +++ b/cm_transfer_credit.py @@ -1,8 +1,8 @@ -from cm_bot_hal import CM_BOT_HAL -import logging, time, requests, json +import logging, time, requests, json, os, threading from concurrent.futures import ThreadPoolExecutor from datetime import datetime -import os + +from cm_bot_hal import CM_BOT_HAL # Suppress httpx logs logging.getLogger("httpx").setLevel(logging.WARNING) @@ -14,16 +14,17 @@ if not os.path.exists(logs_dir): # api_url = 'https://api.luckytown888.net' api_url = 'http://api-server:3000' -max_threading = 1 +max_threading = 5 def transfer(data: dict, local_logger): bot = CM_BOT_HAL() - local_logger.info(f"[Start] Transfer Credit from {data['f_username']} to {data['t_username']}") + thread_name = threading.current_thread().name + local_logger.info(f"[Thread-{thread_name}] [Start] Transfer Credit from {data['f_username']} to {data['t_username']}") result = bot.transfer_credit_api(data['f_username'], data['f_password'], data['t_username'], data['t_password']) - local_logger.info(result) - local_logger.info(f"[Done] {data['f_username']} transfer done!") + local_logger.info(f"[Thread-{thread_name}] {result}") + local_logger.info(f"[Thread-{thread_name}] [Done] {data['f_username']} transfer done!") del bot - time.sleep(0.5) + time.sleep(1) while True: weekday = int(datetime.now().strftime("%w")) @@ -54,4 +55,4 @@ while True: with ThreadPoolExecutor(max_workers=max_threading) as executor: results = list(executor.map(lambda item: transfer(item, local_logger), items)) local_logger.info(f"Completed processing {total_items} transfer items.") - time.sleep(1) + time.sleep(5 * 60) diff --git a/cm_web_view.py b/cm_web_view.py index 7a1c1d6..4d925c1 100644 --- a/cm_web_view.py +++ b/cm_web_view.py @@ -457,17 +457,17 @@ HTML_TEMPLATE = """ ${sortedData.map((acc, index) => ` - ${acc.username || 'N/A'} + ${acc.username} - ${acc.password || 'N/A'} + ${acc.password || ''} - ${acc.status || 'N/A'} + ${acc.status || ''} - ${acc.link || 'N/A'} + ${acc.link || ''} `).join('')} @@ -505,17 +505,17 @@ HTML_TEMPLATE = """ ${sortedData.map((user, index) => ` - ${user.f_username || 'N/A'} + ${user.f_username} - ${user.f_password || 'N/A'} + ${user.f_password || ''} - ${user.t_username || 'N/A'} + ${user.t_username || ''} - ${user.t_password || 'N/A'} + ${user.t_password || ''} - ${user.last_update_time || 'N/A'} + ${user.last_update_time || 'No record'} `).join('')}