+ Update transfer speed

+ Add error handler for getting credit
This commit is contained in:
yiekheng 2025-10-19 10:18:55 +08:00
parent d191821a6a
commit 3fb2786506
2 changed files with 19 additions and 17 deletions

View File

@ -178,20 +178,22 @@ class CM_BOT_HAL:
return float(cm_bot.get_user_credit()) return float(cm_bot.get_user_credit())
def transfer_credit_api(self, f_username: str, f_password: str, t_username: str, t_password: str): def transfer_credit_api(self, f_username: str, f_password: str, t_username: str, t_password: str):
cm_bot = CM_BOT() try:
if cm_bot.login( cm_bot = CM_BOT()
username = f_username, if cm_bot.login(
password = f_password username = f_username,
) == False: password = f_password
return(f'[Fail login] {f_username} cannot login.') ) == False:
amount = round(cm_bot.get_user_credit() - 0.01, 2) return(f'[Fail login] {f_username} cannot login.')
if amount <= 0.01: amount = round(cm_bot.get_user_credit() - 0.01, 2)
return(f'[No enough credit] {f_username} do not have enough credit.') if amount <= 0.01:
if cm_bot.transfer_credit(t_username, t_password, amount) == True: return(f'[No enough credit] {f_username} do not have enough credit.')
return(f'Successfully transfer amount: {amount} from {f_username} to {t_username}') if cm_bot.transfer_credit(t_username, t_password, amount) == True:
else: return(f'Successfully transfer amount: {amount} from {f_username} to {t_username}')
return(f'Fail to transfer credit 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__': if __name__ == '__main__':
bot = CM_BOT_HAL() bot = CM_BOT_HAL()

View File

@ -14,7 +14,7 @@ if not os.path.exists(logs_dir):
# api_url = 'https://api.luckytown888.net' # api_url = 'https://api.luckytown888.net'
api_url = 'http://api-server:3000' api_url = 'http://api-server:3000'
max_threading = 10 max_threading = 20
def transfer(data: dict, local_logger): def transfer(data: dict, local_logger):
bot = CM_BOT_HAL() 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}] {result}")
local_logger.info(f"[Thread-{thread_name}] [Done] {data['f_username']} transfer done!") local_logger.info(f"[Thread-{thread_name}] [Done] {data['f_username']} transfer done!")
del bot del bot
time.sleep(10) time.sleep(5)
while True: while True:
weekday = int(datetime.now().strftime("%w")) weekday = int(datetime.now().strftime("%w"))