From 3fb27865066a5c5e43463aeaf47f8f1fded24eaf Mon Sep 17 00:00:00 2001 From: yiekheng Date: Sun, 19 Oct 2025 10:18:55 +0800 Subject: [PATCH] + Update transfer speed + Add error handler for getting credit --- cm_bot_hal.py | 32 +++++++++++++++++--------------- cm_transfer_credit.py | 4 ++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/cm_bot_hal.py b/cm_bot_hal.py index fefb89f..9022fb2 100644 --- a/cm_bot_hal.py +++ b/cm_bot_hal.py @@ -178,20 +178,22 @@ class CM_BOT_HAL: return float(cm_bot.get_user_credit()) def transfer_credit_api(self, f_username: str, f_password: str, t_username: str, t_password: str): - cm_bot = CM_BOT() - if cm_bot.login( - username = f_username, - password = f_password - ) == False: - return(f'[Fail login] {f_username} cannot login.') - amount = round(cm_bot.get_user_credit() - 0.01, 2) - if amount <= 0.01: - return(f'[No enough credit] {f_username} do not have enough credit.') - if cm_bot.transfer_credit(t_username, t_password, amount) == True: - return(f'Successfully transfer amount: {amount} from {f_username} to {t_username}') - else: - return(f'Fail to transfer credit from {f_username} to {t_username}') - + try: + cm_bot = CM_BOT() + if cm_bot.login( + username = f_username, + password = f_password + ) == False: + return(f'[Fail login] {f_username} cannot login.') + amount = round(cm_bot.get_user_credit() - 0.01, 2) + if amount <= 0.01: + return(f'[No enough credit] {f_username} do not have enough credit.') + if cm_bot.transfer_credit(t_username, t_password, amount) == True: + return(f'Successfully transfer amount: {amount} from {f_username} to {t_username}') + else: + return(f'Fail to transfer credit from {f_username} to {t_username}') + except: + return(f'Fail transfer credit for {f_username}') if __name__ == '__main__': bot = CM_BOT_HAL() @@ -201,4 +203,4 @@ if __name__ == '__main__': # bot.get_user_api() # bot.insert_user_to_table_acc({'username': 'test0001', 'password': 'test0001', 'link': 'test0001'}) # print(bot.get_whatsapp_link_username('https://chat.whatsapp.com/DZDWcicr6MTFrR4kBfnJXO')) - # print(bot.get_user_pass_from_acc('13c4151')) \ No newline at end of file + # print(bot.get_user_pass_from_acc('13c4151')) diff --git a/cm_transfer_credit.py b/cm_transfer_credit.py index 3a21b00..684bafa 100644 --- a/cm_transfer_credit.py +++ b/cm_transfer_credit.py @@ -14,7 +14,7 @@ if not os.path.exists(logs_dir): # api_url = 'https://api.luckytown888.net' api_url = 'http://api-server:3000' -max_threading = 10 +max_threading = 20 def transfer(data: dict, local_logger): bot = CM_BOT_HAL() @@ -24,7 +24,7 @@ def transfer(data: dict, local_logger): 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(10) + time.sleep(5) while True: weekday = int(datetime.now().strftime("%w"))